diff --git a/docker/docker/volumes/camunda_prometheus/prometheus-metrics.yml b/docker/docker/volumes/camunda_prometheus/prometheus-metrics.yml index 96cd1a8..3e64d71 100644 --- a/docker/docker/volumes/camunda_prometheus/prometheus-metrics.yml +++ b/docker/docker/volumes/camunda_prometheus/prometheus-metrics.yml @@ -59,4 +59,40 @@ custom: - collector: /customcollectors/ExternalTasks.groovy enable: true startDelay: 0 - frequency: 5000 \ No newline at end of file + 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 \ No newline at end of file diff --git a/src/main/resources/prometheus/customcollectors/ExternalTasksCustomTopics.groovy b/src/main/resources/prometheus/customcollectors/ExternalTasksCustomTopics.groovy new file mode 100644 index 0000000..e4b5cd7 --- /dev/null +++ b/src/main/resources/prometheus/customcollectors/ExternalTasksCustomTopics.groovy @@ -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 config){ + String engineName = processEngine.getName(); + + config['topics'].each { topicName -> + collectActiveExternalTasksWithTopicName(processEngine, engineName, LOG, (String)topicName ) + } + +} diff --git a/src/main/resources/prometheus/customcollectors/ExternalTasksCustomWorkers.groovy b/src/main/resources/prometheus/customcollectors/ExternalTasksCustomWorkers.groovy new file mode 100644 index 0000000..9956c9b --- /dev/null +++ b/src/main/resources/prometheus/customcollectors/ExternalTasksCustomWorkers.groovy @@ -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 config){ + String engineName = processEngine.getName(); + + config['workers'].each { workerId -> + collectActiveExternalTasksLockedByWorkerId(processEngine, engineName, LOG, (String)workerId) + } + +} diff --git a/src/test/resources/customcollectors/ExternalTasksCustomTopics.groovy b/src/test/resources/customcollectors/ExternalTasksCustomTopics.groovy new file mode 100644 index 0000000..85239cb --- /dev/null +++ b/src/test/resources/customcollectors/ExternalTasksCustomTopics.groovy @@ -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 config){ + String engineName = processEngine.getName(); + + config['topics'].each { topicName -> + collectActiveExternalTasksWithTopicName(processEngine, engineName, LOG, (String)topicName ) + } + +} diff --git a/src/test/resources/customcollectors/ExternalTasksCustomWorkers.groovy b/src/test/resources/customcollectors/ExternalTasksCustomWorkers.groovy new file mode 100644 index 0000000..d604778 --- /dev/null +++ b/src/test/resources/customcollectors/ExternalTasksCustomWorkers.groovy @@ -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 config){ + String engineName = processEngine.getName(); + + config['workers'].each { workerId -> + collectActiveExternalTasksLockedByWorkerId(processEngine, engineName, LOG, (String)workerId) + } + +} diff --git a/src/test/resources/prometheus-metrics.yml b/src/test/resources/prometheus-metrics.yml index ab4a7ed..07e6915 100644 --- a/src/test/resources/prometheus-metrics.yml +++ b/src/test/resources/prometheus-metrics.yml @@ -3,19 +3,19 @@ --- 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 @@ -23,38 +23,74 @@ system: 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 \ No newline at end of file + frequency: 2000 + config: + workers: + - someWorkerJohn + - someOtherWorkerChris + - someLegacyWorkerFrank \ No newline at end of file