pixie
pixie

Reputation: 517

jmx_exporter for prometheus in openshift

We are deploying our microservices in OpenShift. We want to monitor JMX metrics using Prometheus, in order to display them later using Grafana.

We have found the JMX_EXPORTER and as far as I understood it can be used to collect the JMX metrics in Prometheus specific format.

Now, we would like to somehow bind the agent to our code, so that we can access the metrics from inside OpenShift.

Could we somehow deploy the agent / load the agent in our Glassfish, something similar to how Jolokia works? The documentation here https://github.com/prometheus/jmx_exporter didn't bring us too far.

Upvotes: 0

Views: 2207

Answers (1)

misiek
misiek

Reputation: 21

A bit late, but I just spent a few hours trying to get the same done and there is very little info out there, so here is what I ended up with just in case it helps somebody.

This assumes you have prometeus agent already running in your openshift (default in 3.9)

  • first activate your jmx_exporter by adding

    -javaagent:/path/to/jmx_prometheus_javaagent-0.3.1.jar=8080:/path/to/jmx.yaml

to your app invocation - the jmx.yaml can contain several things, but the most important are extraction rules - they are highly specific to your app. for example mine looks something like that:

startDelaySeconds: 0
ssl: false
rules:
- pattern : "kafka.consumer<type=(.+), client-id=(.+)-([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12})-StreamThread-([0-9]+)(.*), topic=(.+)><>(.+): "
 name: dataplatform_$1_$7
  labels:
 clientId: "$2"
 fullClientId: "$2$5"
 clientUUID: "$3"
 threadNum: "$4"
 extraClientName: "$5"
 topic: "$6"

Second step is to add appropriate annotations and expose ports. Add following to your deployment yaml:

template:
   metadata:
      annotations:
        openshift.io/generated-by: OpenShiftWebConsole
        prometheus.io/path: /metrics 
        prometheus.io/port: "8080" 
        prometheus.io/scrape: "true"

and than expose the port on the container:

ports:
- containerPort: 8080
   protocol: TCP

Your prometheus should be collecting the metrics now. You should also see the metrics if you hit port 8080 on your pod.

Last step is to add Prometeus data source to your Grafana and start enjoying your metrics

Upvotes: 2

Related Questions