Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Prometheus' JMX exporter java agent to collect custom metrics

I'd like to use Prometheus' JMX exporter to collect custom application metrics using Prometheus. I have an application that I've packaged into a jar file ApplicationToMonitor.jar-- it exposes port 8989 and declares Prometheus metrics, but doesn't expose an end-point for prometheus to scrape (from what I've read, the prometheus javaagent takes care of this).

I'm not sure what the configuration.yaml file should look like. Also, why is it recommended that one use the shaded.io.prometheus library (and register new metric variables under the default registry) as opposed to the regular io.prometheus library and not using a registry at all?

I'm referencing the Prometheus JMX exporter documentation, just simply not understanding the aforementioned components.

like image 535
prometheusnoob Avatar asked Jun 26 '18 08:06

prometheusnoob


People also ask

What is Prometheus JMX exporter?

That's the job of the Prometheus JMX Exporter. The exporter connects to Java's native metric collection system, Java Management Extensions (JMX), and converts the metrics into a format that Prometheus can understand. In this post, I'll use Kafka as an example of a Java application that you want to monitor.


1 Answers

You would only use the JMX exporter for code you don't control that's exposing JMX metrics. In this case you need to add some exposition per https://github.com/prometheus/client_java#http. The HTTPServer is simplest.

like image 98
brian-brazil Avatar answered Oct 19 '22 13:10

brian-brazil