This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add External Task Custom Configurable Scripts for Topics and WorkerId
Configurable through the YAML `config` key. see yaml files for examples
- Loading branch information
1 parent
7e64514
commit 6f40ebc
Showing
6 changed files
with
285 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/resources/prometheus/customcollectors/ExternalTasksCustomTopics.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package prometheus.customcollectors; | ||
|
||
import io.digitalstate.camunda.prometheus.collectors.SimpleGaugeMetric | ||
import io.digitalstate.camunda.prometheus.config.yaml.CustomMetricsConfig; | ||
import org.camunda.bpm.engine.ProcessEngine; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* External Task Collector for specific array of Topic Names | ||
* Can be reused multiple times within YAML configuration to create different timed collections | ||
*/ | ||
|
||
CustomMetricsConfig configs = config | ||
collectAll((ProcessEngine)processEngine, (Logger)LOGGER, configs.getConfig()) | ||
|
||
/** | ||
* Collect count of Active External Tasks with a specific Topic Name. | ||
* @param processEngine | ||
* @param engineName | ||
*/ | ||
static void collectActiveExternalTasksWithTopicName(ProcessEngine processEngine, String engineName, Logger LOG, String topicName){ | ||
SimpleGaugeMetric counter = new SimpleGaugeMetric( | ||
"active_external_tasks_with_topicname", | ||
"The number of active external tasks with a Topic Name label", | ||
Arrays.asList("engine_name", "topic_name") | ||
); | ||
|
||
long count = processEngine.getExternalTaskService() | ||
.createExternalTaskQuery() | ||
.active() | ||
.topicName(topicName) | ||
.count() | ||
|
||
LOG.debug("Collecting Metric Number of Active External Tasks with a topic name: ${topicName}: ${count}"); | ||
|
||
counter.setValue(count, Arrays.asList(engineName, topicName)); | ||
} | ||
|
||
/** | ||
* Collects all collectors defined in this class. | ||
* @param processEngine | ||
*/ | ||
static void collectAll(ProcessEngine processEngine, Logger LOG, Map<String, Object> config){ | ||
String engineName = processEngine.getName(); | ||
|
||
config['topics'].each { topicName -> | ||
collectActiveExternalTasksWithTopicName(processEngine, engineName, LOG, (String)topicName ) | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/resources/prometheus/customcollectors/ExternalTasksCustomWorkers.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package prometheus.customcollectors; | ||
|
||
import io.digitalstate.camunda.prometheus.collectors.SimpleGaugeMetric | ||
import io.digitalstate.camunda.prometheus.config.yaml.CustomMetricsConfig; | ||
import org.camunda.bpm.engine.ProcessEngine; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* External Task Collector for specific array of Worker Id | ||
* Can be reused multiple times within YAML configuration to create different timed collections | ||
*/ | ||
|
||
CustomMetricsConfig configs = config | ||
collectAll((ProcessEngine)processEngine, (Logger)LOGGER, configs.getConfig()) | ||
|
||
/** | ||
* Collect count of Active External Tasks that have most recently been locked by a given worker. | ||
* @param processEngine | ||
* @param engineName | ||
*/ | ||
static void collectActiveExternalTasksLockedByWorkerId(ProcessEngine processEngine, String engineName, Logger LOG, String workerId){ | ||
SimpleGaugeMetric counter = new SimpleGaugeMetric( | ||
"active_external_tasks_locked_by_workerid", | ||
"The number of active external tasks that have been most recently locked by worker ID", | ||
Arrays.asList("engine_name", "worker_id") | ||
); | ||
|
||
long count = processEngine.getExternalTaskService() | ||
.createExternalTaskQuery() | ||
.active() | ||
.workerId(workerId) | ||
.count() | ||
|
||
LOG.debug("Collecting Metric Number of Active External Tasks that have most recently been locked by worker ID: ${workerId}: ${count}"); | ||
|
||
counter.setValue(count, Arrays.asList(engineName, workerId)); | ||
} | ||
|
||
/** | ||
* Collects all collectors defined in this class. | ||
* @param processEngine | ||
*/ | ||
static void collectAll(ProcessEngine processEngine, Logger LOG, Map<String, Object> config){ | ||
String engineName = processEngine.getName(); | ||
|
||
config['workers'].each { workerId -> | ||
collectActiveExternalTasksLockedByWorkerId(processEngine, engineName, LOG, (String)workerId) | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/test/resources/customcollectors/ExternalTasksCustomTopics.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package customcollectors; | ||
|
||
import io.digitalstate.camunda.prometheus.collectors.SimpleGaugeMetric | ||
import io.digitalstate.camunda.prometheus.config.yaml.CustomMetricsConfig; | ||
import org.camunda.bpm.engine.ProcessEngine; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* External Task Collector for specific array of Topic Names | ||
* Can be reused multiple times within YAML configuration to create different timed collections | ||
*/ | ||
|
||
CustomMetricsConfig configs = config | ||
collectAll((ProcessEngine)processEngine, (Logger)LOGGER, configs.getConfig()) | ||
|
||
/** | ||
* Collect count of Active External Tasks with a specific Topic Name. | ||
* @param processEngine | ||
* @param engineName | ||
*/ | ||
static void collectActiveExternalTasksWithTopicName(ProcessEngine processEngine, String engineName, Logger LOG, String topicName){ | ||
SimpleGaugeMetric counter = new SimpleGaugeMetric( | ||
"active_external_tasks_with_topicname", | ||
"The number of active external tasks with a Topic Name label", | ||
Arrays.asList("engine_name", "topic_name") | ||
); | ||
|
||
long count = processEngine.getExternalTaskService() | ||
.createExternalTaskQuery() | ||
.active() | ||
.topicName(topicName) | ||
.count() | ||
|
||
LOG.debug("Collecting Metric Number of Active External Tasks with a topic name: ${topicName}: ${count}"); | ||
|
||
counter.setValue(count, Arrays.asList(engineName, topicName)); | ||
} | ||
|
||
/** | ||
* Collects all collectors defined in this class. | ||
* @param processEngine | ||
*/ | ||
static void collectAll(ProcessEngine processEngine, Logger LOG, Map<String, Object> config){ | ||
String engineName = processEngine.getName(); | ||
|
||
config['topics'].each { topicName -> | ||
collectActiveExternalTasksWithTopicName(processEngine, engineName, LOG, (String)topicName ) | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/test/resources/customcollectors/ExternalTasksCustomWorkers.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package customcollectors; | ||
|
||
import io.digitalstate.camunda.prometheus.collectors.SimpleGaugeMetric | ||
import io.digitalstate.camunda.prometheus.config.yaml.CustomMetricsConfig; | ||
import org.camunda.bpm.engine.ProcessEngine; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* External Task Collector for specific array of Worker Id | ||
* Can be reused multiple times within YAML configuration to create different timed collections | ||
*/ | ||
|
||
CustomMetricsConfig configs = config | ||
collectAll((ProcessEngine)processEngine, (Logger)LOGGER, configs.getConfig()) | ||
|
||
/** | ||
* Collect count of Active External Tasks that have most recently been locked by a given worker. | ||
* @param processEngine | ||
* @param engineName | ||
*/ | ||
static void collectActiveExternalTasksLockedByWorkerId(ProcessEngine processEngine, String engineName, Logger LOG, String workerId){ | ||
SimpleGaugeMetric counter = new SimpleGaugeMetric( | ||
"active_external_tasks_locked_by_workerid", | ||
"The number of active external tasks that have been most recently locked by worker ID", | ||
Arrays.asList("engine_name", "worker_id") | ||
); | ||
|
||
long count = processEngine.getExternalTaskService() | ||
.createExternalTaskQuery() | ||
.active() | ||
.workerId(workerId) | ||
.count() | ||
|
||
LOG.debug("Collecting Metric Number of Active External Tasks that have most recently been locked by worker ID: ${workerId}: ${count}"); | ||
|
||
counter.setValue(count, Arrays.asList(engineName, workerId)); | ||
} | ||
|
||
/** | ||
* Collects all collectors defined in this class. | ||
* @param processEngine | ||
*/ | ||
static void collectAll(ProcessEngine processEngine, Logger LOG, Map<String, Object> config){ | ||
String engineName = processEngine.getName(); | ||
|
||
config['workers'].each { workerId -> | ||
collectActiveExternalTasksLockedByWorkerId(processEngine, engineName, LOG, (String)workerId) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters