13.3. Extending Prometheus metrics monitoring in Decision Server with custom metrics
After you configure your Decision Server instance to use Prometheus metrics monitoring, you can extend the Prometheus functionality in Decision Server to use custom metrics according to your business needs. Prometheus then collects and stores your custom metrics along with the default metrics that Decision Server exposes with Prometheus.
As an example, this procedure defines custom Decision Model and Notation (DMN) metrics to be collected and stored by Prometheus.
Prerequisites
- Prometheus metrics monitoring is configured for your Decision Server instance. For information about Prometheus configuration with Decision Server on-premise, see 「Configuring Prometheus metrics monitoring for Decision Server」. For information about Prometheus configuration with Decision Server on Red Hat OpenShift Container Platform, see 「Configuring Prometheus metrics monitoring for Decision Server on Red Hat OpenShift Container Platform」.
Procedure
Create an empty Maven project and define the following packaging type and dependencies in the
pom.xml
file for the project:Example pom.xml file in the sample project
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Implement the relevant listener from the
org.kie.server.services.prometheus.PrometheusMetricsProvider
interface as part of the custom listener class that defines your custom Prometheus metrics, as shown in the following example:Sample implementation of the
DMNRuntimeEventListener
listener in a custom listener classCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
PrometheusMetricsProvider
interface contains the required listeners for collecting Prometheus metrics. The interface is incorporated by thekie-server-services-prometheus
dependency that you declared in your projectpom.xml
file.In this example, the
ExampleCustomPrometheusMetricListener
class implements theDMNRuntimeEventListener
listener (from thePrometheusMetricsProvider
interface) and defines the custom DMN metrics to be collected and stored by Prometheus.Implement the
PrometheusMetricsProvider
interface as part of a custom metrics provider class that associates your custom listener with thePrometheusMetricsProvider
interface, as shown in the following example:Sample implementation of the
PrometheusMetricsProvider
interface in a custom metrics provider classCopy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, the
MyPrometheusMetricsProvider
class implements thePrometheusMetricsProvider
interface and includes your customExampleCustomPrometheusMetricListener
listener class.-
To make the new metrics provider discoverable for Decision Server, create a
META-INF/services/org.kie.server.services.prometheus.PrometheusMetricsProvider
file in your Maven project and add the fully qualified class name of thePrometheusMetricsProvider
implementation class within the file. For this example, the file contains the single lineorg.kie.server.ext.prometheus.MyPrometheusMetricsProvider
. -
Build your project and copy the resulting JAR file into the
~/kie-server.war/WEB-INF/lib
directory of your project. For example, on Red Hat JBoss EAP, the path to this directory isEAP_HOME/standalone/deployments/kie-server.war/WEB-INF/lib
. Start the Decision Server and deploy the built project to the running Decision Server. You can deploy the project using the Business Central interface or the Decision Server REST API (a
PUT
request tohttp://SERVER:PORT/kie-server/services/rest/server/containers/{containerId}
).After your project is deployed on a running Decision Server, Prometheus begins collecting metrics and Decision Server publishes the metrics to the REST API endpoint
http://HOST:PORT/SERVER/services/rest/metrics
(or on Spring Boot, tohttp://HOST:PORT/rest/metrics
).