How to use Prometheus' JMXCollector to collect metrics over multiple iterations

146 views
Skip to first unread message

MUSTAJIB MOHAMMED KHAN

unread,
Jul 24, 2023, 4:53:28 AM7/24/23
to Prometheus Users

I need to create a Java application which collects JMX metrics from a running java process. For this, I am using the JMXCollector class. I couldn't find the option in this to configure it for multiple iterations.

I have a Java wrapper around this to schedule collection after a specified time and for a specified number of iterations. I would like to understand if there is an already existing class that I can use.

Doug Hoard

unread,
Jul 24, 2023, 8:16:40 PM7/24/23
to Prometheus Users
I'm not aware of any code that performs what you are trying to accomplish. Do you actually need access to the List<MetricFamilySamples> returned during the collection?

Typically, a Java application would use the Prometheus JMX Exporter (as a Java agent) to expose the metrics via HTTP(S). Your application could start, pause for a specific period of time, then call the JMX Exporter REST API on an interval (or for a specific number of iterations), capturing the output, and parsing it.

Here is a link to the Java class used to parse the REST API output used by the integration tests:

Moe

unread,
Jul 25, 2023, 2:55:23 AM7/25/23
to Prometheus Users
Thanks, Doug I'll look into using the Rest API output.

Yeah, I would need access to List<MetricFamilySamples> returned during collection.

I see that the config file used in Prometheus has a scrape interval defined. Does this call the JMX collector?

Doug Hoard

unread,
Jul 25, 2023, 7:19:09 AM7/25/23
to Prometheus Users
Prometheus can be configured to scrape the JMX Exporter (or any other Prometheus exposition (output) compliant URL.)

Moe

unread,
Jul 25, 2023, 8:08:56 AM7/25/23
to Prometheus Users
Oh, that makes sense. Also, does this mean the scraping interval logic resides in Prometheus?

Doug Hoard

unread,
Jul 25, 2023, 8:29:33 AM7/25/23
to Prometheus Users
Correct.
Reply all
Reply to author
Forward
0 new messages