Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenOTT committed Apr 22, 2021
1 parent 7ba9995 commit 81c3cf1
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 101 deletions.
64 changes: 10 additions & 54 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
# Created by .ignore support plugin (hsz.mobi)
### Java template
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
*.iml

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

Thumbs.db
.DS_Store
.gradle
build/
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

.settings
bin/
build-reports/

# Eclipse
.classpath
.project
.settings/

# Intellij
.idea/
out/
.idea
*.iml
*.ipr
*.iws

# Mac
.DS_Store

# Maven
log/

#docker/**/*.jar
.project
.settings
.classpath
77 changes: 51 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Camunda Monitoring

"Camunda Monitoring" is a process engine plugin that provides the Camunda BPM engine with configurable and script based metric data.
"Camunda Monitoring" is a process engine plugin that provides the Camunda BPM engine with configurable and script
based metric data.

The data can be consumed by numerous monitoring systems such as Prometheus.

This project is a replacement for: https://github.com/StephenOTT/camunda-prometheus-process-engine-plugin
Expand All @@ -12,57 +14,59 @@ provide a [generic metrics facade that supports numerous monitoring systems](htt
Due to popularity of Prometheus, this documentation makes the assumption that Prometheus will be used as the monitoring
system, but you should be able to replace the dependency of Prometheus with any other Micrometer supported system/dependency.

Metric monitoring for a BPM engine can be a resource intensive task depending on the size of your database, and your queries/metrics you want to monitor.
Metric monitoring for a BPM engine can be a resource intensive task depending on the size of your database,
and your queries/metrics you want to monitor.

This plugin is designed to be used in Camunda run as a drop-in plugin, or as a custom dependency added to your Camunda Spring Boot project.
This plugin is designed to be used in Camunda run as a drop-in plugin, or as a custom dependency added to your
Camunda Spring Boot project.

![arch](./docs/Camunda-Monitoring-Arch.png)

# Camunda-Run Quick Start with Prometheus

1. Download the Process Engine Plugin Jar from [Releases](https://github.com/StephenOTT/Camunda-Monitoring/releases) (Use the release that includes the Prometheus dependency)
1. Run the Docker-compose file. See the docker folder
1. Download the Camunda-Monitoring Jar from [Releases](https://github.com/StephenOTT/Camunda-Monitoring/releases) and copy it into the docker folder.
1. Configure your DB connections in the default.yml file.
1. Run the Docker-compose file. See the docker folder.

The docker-compose will deploy a Camunda-Run instance with the Camunda job-executor disabled. The engine instance should be used solely for monitoring purposes.
The docker-compose will deploy a Camunda-Run instance with the Camunda job-executor disabled.
The engine instance should be used solely for monitoring purposes.

Defaults:

1. all Spring Boot Actuator metrics that are enabled by default have been disabled and only Camunda metrics should remain.
1. All Spring Boot Actuator metrics that are enabled by default have been disabled and only Camunda metrics should remain.
1. A volume will be mounted for `/metrics/CamundaMonitoringMetrics.groovy`, where you add/remove/modify any metrics you choose.
1. prometheus metrics should be exposed as:`http://localhost:8080/actuator/prometheus`
1. The Prometheus metrics are exposed at:`http://localhost:8080/actuator/prometheus`


After making changes to the CamundaMonitoringMetrics.groovy file, you must restart the Camunda instance with the Camunda Monitoring Plugin for changes to take effect.
After making changes to the CamundaMonitoringMetrics.groovy file, you must restart the Camunda instance with the
Camunda Monitoring Plugin for changes to take effect.

# Prometheus Setup and Grafana Reporting

[See Prometheus configuration requirements from Spring Boot Actuator](https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-metrics-export-prometheus)

.... more to come...
Deploy any typical Prometheus/Grafana setup with Prometheus configuration as per [Spring Boot Actuator Docs](https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-metrics-export-prometheus)

# Default Metrics

Part of `CamundaMonitoringMetrics.groovy`

1. Active Incidents Count
1. Active Process Instances Count
1. Completed Process Instances Count
1. [Open a request](https://github.com/StephenOTT/Camunda-Monitoring/issues/new) if you want a specific metric created


# Advanced Configuration

## Metric Beans Configuration
## Monitoring Beans Configuration

Metric beans are made available to the engine through a "beans configuration" file:
Monitoring beans are made available to the engine through a "beans configuration" file:

Application Yml Path: `camunda.bpm.metrics.monitoringBeansXml`.
Default: `/file:/camunda/configuration/camunda-monitoring-beans.xml` which is for optimal Camunda Run usage.
Spring Config Yml Path: `camunda.bpm.metrics.monitoringBeansXml`.
Default: `file:/camunda/configuration/camunda-monitoring-beans.xml` which is for optimal Camunda Run usage.

Takes a classpath resource or a file:

Example:

`camunda.bpm.metrics.monitoringBeansXml: /file:/camunda/configuration/camunda-monitoring-beans.xml`
`camunda.bpm.metrics.monitoringBeansXml: file:/camunda/configuration/camunda-monitoring-beans.xml`

or

Expand All @@ -82,22 +86,35 @@ camunda-metric-beans.xml:

<lang:defaults proxy-target-class="true"/>

<lang:groovy id="processInstanceMetrics" script-source="/metrics/ProcessInstanceMetrics.groovy"/>
<lang:groovy id="incidentMetrics" script-source="/metrics/IncidentMetrics.groovy"/>

<!-- <lang:groovy id="camundaMonitoringMetrics" script-source="/metrics/CamundaMonitoringMetrics.groovy"/>-->

<lang:groovy id="camundaMonitoringMetrics" script-source="file:/metrics/CamundaMonitoringMetrics.groovy"/>


<!-- <lang:groovy id="processInstanceMetrics" script-source="/metrics/ProcessInstanceMetrics.groovy"/>-->
<!-- <lang:groovy id="incidentMetrics" script-source="/metrics/IncidentMetrics.groovy"/>-->

</beans>
```

`script-source` will look in the classpath by default. If your groovy files are outside of your jar, then you can use the `file:` prefix to set the path in the filesystem such as:
`script-source` will look in the classpath by default. If your groovy files are external to the jar, then you can use the `file:` prefix to set the path in the filesystem such as:

`<lang:groovy id="incidentMetrics" script-source="file:/someFolder/IncidentMetrics.groovy" proxy-target-class="true"/>`
`<lang:groovy id="incidentMetrics" script-source="file:/someFolder/IncidentMetrics.groovy"/>`


## Application.yml configuration:
## Spring Boot configuration:

Add the following to your `application.yml`.
Add the following to your Spring Boot Config (such as `application.yml`) .

```yml
# Configure your DB connection:
#spring:
# datasource:
# url: jdbc:h2:./build/DB/dbdevDb1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=TRUE # jdbc:h2:~/devDb1;MODE=PostgreSQL;AUTO_SERVER=TRUE
# username: sa
# password: ''

management:
endpoints:
web:
Expand All @@ -113,14 +130,22 @@ management:
system: false
jdbc: false
http: false

camunda:
bpm:
# If you have a custom monitoring-beans path location you can define it:
# metrics:
# monitoringBeansXml: file:/camunda/configuration/camunda-monitoring-beans.xml
job-execution:
enabled: false
```
If you want to benefit from the other metrics provided by Spring Boot Actuator then you can enable them under `management.metrics.enable:...`.

See the [Actuator](https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-metrics-export-prometheus) documentation for further details


# Example Metric File
# Example Monitoring Metrics File

```groovy
Expand Down
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.jar
20 changes: 20 additions & 0 deletions docker/camunda-monitoring-beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/lang https://www.springframework.org/schema/lang/spring-lang.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

<!-- https://docs.spring.io/spring-framework/docs/current/reference/html/languages.html#groovy-->

<lang:defaults proxy-target-class="true"/>


<!-- <lang:groovy id="camundaMonitoringMetrics" script-source="/metrics/CamundaMonitoringMetrics.groovy"/>-->

<lang:groovy id="camundaMonitoringMetrics" script-source="file:/metrics/CamundaMonitoringMetrics.groovy"/>


<!-- <lang:groovy id="processInstanceMetrics" script-source="/metrics/ProcessInstanceMetrics.groovy"/>-->
<!-- <lang:groovy id="incidentMetrics" script-source="/metrics/IncidentMetrics.groovy"/>-->

</beans>
28 changes: 28 additions & 0 deletions docker/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-#spring:
# datasource:
# url: jdbc:h2:./build/DB/dbdevDb1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=TRUE # jdbc:h2:~/devDb1;MODE=PostgreSQL;AUTO_SERVER=TRUE
# username: sa
# password: ''

management:
endpoints:
web:
exposure:
include: prometheus
metrics:
enable:
jvm: false
hikaricp: false
process: false
logback: false
tomcat: false
system: false
jdbc: false
http: false

camunda:
bpm:
# metrics:
# monitoringBeansXml: file:/camunda/configuration/camunda-monitoring-beans.xml
job-execution:
enabled: false
10 changes: 10 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
camunda-monitoring:
image: camunda/camunda-bpm-platform:run-latest
ports:
- "8080:8080"
volumes:
- ./Camunda-Monitoring.jar:/camunda/configuration/userlib/Camunda-Monitoring.jar
- ./metrics:/metrics
- ./camunda-monitoring-beans.xml:/camunda/configuration/camunda-monitoring-beans.xml
- ./default.yml:/camunda/configuration/default.yml
39 changes: 39 additions & 0 deletions docker/metrics/CamundaMonitoringMetrics.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import io.micrometer.core.instrument.MeterRegistry
import io.micrometer.core.instrument.Tag
import org.camunda.bpm.engine.ProcessEngine
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.scheduling.annotation.Scheduled

import javax.annotation.PostConstruct
import java.util.concurrent.atomic.AtomicLong

/**
* The generic Camunda Monitoring metrics groovy file.
*
* This can be used as a quick start catch all file to add any metrics you want to monitor.
*
* Advanced use cases may wish to separate metrics into multiple groovy files.
*/
class CamundaMonitoringMetrics {

@Autowired MeterRegistry registry
@Autowired ProcessEngine processEngine

String namespace = "camunda"
String activeIncidentsMetricName = "${namespace}_active_incidents"

List<Tag> commonTags

AtomicLong activeIncidents

@PostConstruct
void setup(){
commonTags = [Tag.of("engineName", processEngine.getName())]
activeIncidents = registry.gauge(activeIncidentsMetricName, commonTags, new AtomicLong(0))
}

@Scheduled(fixedRate = 60000L)
void getActiveIncidents(){
activeIncidents.set(processEngine.getRuntimeService().createIncidentQuery().count())
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

val kotlinVersion: String by project
val spekVersion: String by project
val camundaVersion: String by project
Expand All @@ -10,30 +12,32 @@ plugins {
id("org.jetbrains.kotlin.plugin.spring")
}


dependencies {

implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
// implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")

compileOnly(platform("org.camunda.bpm:camunda-bom:$camundaVersion"))
compileOnly("org.camunda.bpm:camunda-engine")

// compileOnly("org.camunda.bpm:camunda-engine-plugin-spin")
// compileOnly("org.camunda.spin:camunda-spin-dataformat-json-jackson")


implementation("org.codehaus.groovy:groovy-all:3.0.7")

compileOnly("org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter")
compileOnly("org.springframework.boot:spring-boot-starter-web")

implementation("org.codehaus.groovy:groovy-all:3.0.7")
implementation("org.springframework.boot:spring-boot-starter-actuator:latest.release")
implementation("io.micrometer:micrometer-registry-prometheus:latest.release")

implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("io.micrometer:micrometer-registry-prometheus")
implementation("org.springframework.boot:spring-boot-starter-actuator:latest.release")
implementation("io.micrometer:micrometer-registry-prometheus:latest.release")

}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<ShadowJar> {
archiveFileName.set("Camunda-Monitoring.jar")
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.camunda.bpm.run.plugin.prometheus
package org.camunda.bpm.run.plugin.monitoring

import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.ImportResource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.camunda.bpm.run.plugin.prometheus
package org.camunda.bpm.run.plugin.monitoring

import org.camunda.bpm.engine.impl.cfg.AbstractProcessEnginePlugin
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = "CamundaPrometheusMetricsPlugin"
include("prometheusmetricsplugin", "springboot")
rootProject.name = "CamundaMonitoring"
include("monitoringplugin", "springboot")
Loading

0 comments on commit 81c3cf1

Please sign in to comment.