Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
Add External Task Custom Configurable Scripts for Topics and WorkerId
Browse files Browse the repository at this point in the history
Configurable through the YAML `config` key.  see yaml files for examples
  • Loading branch information
StephenOTT committed Oct 19, 2018
1 parent 7e64514 commit 6f40ebc
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 13 deletions.
38 changes: 37 additions & 1 deletion docker/docker/volumes/camunda_prometheus/prometheus-metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,40 @@ custom:
- collector: /customcollectors/ExternalTasks.groovy
enable: true
startDelay: 0
frequency: 5000
frequency: 5000
- collector: classpath:prometheus/customcollectors/ExternalTasksCustomTopics.groovy
enable: true
startDelay: 0
frequency: 10000
config:
topics:
- myTopic1
- myTopic2
- someCustomTopic
- collector: classpath:prometheus/customcollectors/ExternalTasksCustomTopics.groovy
enable: true
startDelay: 0
frequency: 8000
config:
topics:
- myTopic3
- myTopic4
- someOtherCustomTopic
- collector: classpath:prometheus/customcollectors/ExternalTasksCustomWorkers.groovy
enable: true
startDelay: 0
frequency: 2000
config:
workers:
- someWorkerID123
- someOtherWorkerId567890
- someLegacyWorker001
- collector: classpath:prometheus/customcollectors/ExternalTasksCustomWorkers.groovy
enable: true
startDelay: 0
frequency: 2000
config:
workers:
- SW1
- SW2
- SW3
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 )
}

}
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)
}

}
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 )
}

}
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)
}

}
60 changes: 48 additions & 12 deletions src/test/resources/prometheus-metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,94 @@
---
system:
- collector: io.digitalstate.camunda.prometheus.collectors.camunda.BpmnExecution
enable: true
enable: false
startDate: 2015-10-03T17:59:38+00:00
endDate: now
startDelay: 0
frequency: 5000
- collector: io.digitalstate.camunda.prometheus.collectors.camunda.DmnExecution
enable: true
enable: false
startDate: 2015-10-03T17:59:38+00:00
endDate: now
startDelay: 0
frequency: 5000
- collector: io.digitalstate.camunda.prometheus.collectors.camunda.JobExecutor
enable: true
enable: false
startDate: 2015-10-03T17:59:38+00:00
endDate: now
startDelay: 0
frequency: 5000

custom:
- collector: ./target/test-classes/customcollectors/UserTasks.groovy
enable: true
enable: false
startDelay: 0
frequency: 5000
- collector: ./target/test-classes/customcollectors/BpmnProcessDefinition.groovy
enable: true
enable: false
startDelay: 0
frequency: 5000
- collector: ./target/test-classes/customcollectors/EventsMetrics.groovy
enable: true
enable: false
startDelay: 0
frequency: 5000
- collector: ./target/test-classes/customcollectors/IdentityServiceMetrics.groovy
enable: true
enable: false
startDelay: 0
frequency: 5000
- collector: classpath:/prometheus/customcollectors/IncidentMetrics.groovy
enable: true
enable: false
startDelay: 0
frequency: 5000
- collector: classpath:/prometheus/customcollectors/ProcessInstances.groovy
enable: true
enable: false
startDelay: 0
frequency: 5000
- collector: classpath:prometheus/customcollectors/TimerMetrics.groovy
enable: true
enable: false
startDelay: 0
frequency: 5000
- collector: ./target/test-classes/customcollectors/UserOperationLog.groovy
enable: true
enable: false
startDelay: 0
frequency: 5000
- collector: ./target/test-classes/customcollectors/ExternalTasks.groovy
enable: false
startDelay: 0
frequency: 5000
- collector: ./target/test-classes/customcollectors/ExternalTasksCustomTopics.groovy
enable: true
startDelay: 0
frequency: 10000
config:
topics:
- myTopic1
- myTopic2
- someCustomTopic
- collector: ./target/test-classes/customcollectors/ExternalTasksCustomTopics.groovy
enable: true
startDelay: 0
frequency: 8000
config:
topics:
- myTopic3
- myTopic4
- someOtherCustomTopic
- collector: ./target/test-classes/customcollectors/ExternalTasksCustomWorkers.groovy
enable: true
startDelay: 0
frequency: 2000
config:
workers:
- someWorkerID123
- someOtherWorkerId567890
- someLegacyWorker001
- collector: ./target/test-classes/customcollectors/ExternalTasksCustomWorkers.groovy
enable: true
startDelay: 0
frequency: 5000
frequency: 2000
config:
workers:
- someWorkerJohn
- someOtherWorkerChris
- someLegacyWorkerFrank

0 comments on commit 6f40ebc

Please sign in to comment.