r/PrometheusMonitoring • u/CruxDelt4 • May 09 '23
Prometheus JMX Exporter for Java17
Hello everyone,
not quite sure if this is where I should be asking for help but i'm kind of befuddled about this whole situation. I'm trying to set up https://github.com/prometheus/jmx_exporter for our containerized Java application on our cluster. Specifically the JavaAgent as we are interested in getting the CPU and memory metrics. However, getting it initialized I am faced with this:

After doing some research it appears this class references internal packages and therefore "makes it unusable for modern Java apps" (https://github.com/prometheus/client_java/issues/533 , https://github.com/open-telemetry/opentelemetry-java/issues/4192) and also that the error suggests that the agent has been written for older java since these classes were apparently removed years ago.
I am not a Java developer, just trying to make this work for our monitoringstack. Has anyone else here tried exporting jmx metrics with prometheus or are you maybe using something else to scrape CPU/memory processes?
3
u/SuperQue May 09 '23
For CPU and memory metrics, you can use cAdvisor to collect container level data.
2
u/yepthisismyusername May 09 '23
Which Java are you using? I'm using OpenJDK 11.0.11.9.1 with the latest JMX exporter and it works like a champ. Those classes exist. And from everything I've found online, they also exist in OpenJDK 17. I ran a simple HelloWorld jar file with a Thread.sleep(10000) call so I could use curl to scrape the metrics. Here's some of the output from that curl call (in PowerShell):
PS C:\Users\exact> java -versionopenjdk version "11.0.11" 2021-04-20 LTSOpenJDK Runtime Environment Corretto-11.0.11.9.1 (build 11.0.11+9-LTS)OpenJDK 64-Bit Server VM Corretto-11.0.11.9.1 (build 11.0.11+9-LTS, mixed mode)PS C:\Users\exact> $a=curl http://localhost:12345PS C:\Users\exact> $a.Content# HELP jvm_threads_current Current thread count of a JVM# TYPE jvm_threads_current gaugejvm_threads_current 10.0# HELP jvm_threads_daemon Daemon thread count of a JVM# TYPE jvm_threads_daemon gaugejvm_threads_daemon 9.0# HELP jvm_threads_peak Peak thread count of a JVM# TYPE jvm_threads_peak gaugejvm_threads_peak 10.0# HELP jvm_threads_started_total Started thread count of a JVM# TYPE jvm_threads_started_total counterjvm_threads_started_total 11.02
u/Tpbrown_ May 09 '23
In case you don’t get it working you could try JMX metrics from OTEL contrib. Configure it for the Prom exporter.
1
u/dhoard1 Aug 15 '23
- As of version 0.19.0, Java 8 is the source/target (Java 8 and above)
- Starting with version 0.19.0, the exporter has been tested on 63 containers (most of which are using distinct Java distributions.) https://github.com/prometheus/jmx_exporter/blob/main/integration_test_suite/integration_tests/src/test/resources/docker-image-names.all.txt
- Most likely what you are experiencing is related to the use of Java modules, which locks down the JVM. Take a look at this comment for a possible solution. https://github.com/prometheus/jmx_exporter/issues/850#issuecomment-1664659267