I am trying to integrate jvm metrics to my akka application. I used prometheus jmx exporter. Instead of using the whole app and running it as java agent, I used only the exporter and integrated to my existing prometheus registry
import io.prometheus.jmx.JmxCollector
val jmxCollector: JmxCollector = new JmxCollector(getClass.getResourceAsStream("jmx-config.yaml"))
jmxCollector.register(prometheusRegistry)
I am able to see the metrics but few metrics starting with prefix jvm are missing compared to other applications which are running the exporter as java agent. Like thread metrics which are missing
# HELP jvm_threads_state Current count of threads by state
# TYPE jvm_threads_state gauge
jvm_threads_state{state="TERMINATED",} 0.0
jvm_threads_state{state="RUNNABLE",} 10.0
jvm_threads_state{state="TIMED_WAITING",} 11.0
jvm_threads_state{state="WAITING",} 37.0
jvm_threads_state{state="NEW",} 0.0
jvm_threads_state{state="BLOCKED",} 0.0
My metrics config is bare minimum and looks like this in both the applications
---
startDelaySeconds: 10
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
Could you please help me understand what could be the difference that is causing this problem.
This is the expected behaviour
This exporter is intended to be run as a Java Agent, exposing a HTTP server and serving metrics of the local JVM. It can be also run as a standalone HTTP server and scrape remote JMX targets, but this has various disadvantages, such as being harder to configure and being unable to expose process metrics (e.g., memory and CPU usage).
The "being unable to expose process metrics" is a subtle reference to the jvm_*
metrics like
jvm_classes_loaded
jvm_classes_loaded_total
jvm_threads_current
jvm_threads_daemon
jvm_memory_used_bytes
(There is no such thing as jvm_memory_bytes_used
in client_java)jvm_memory_pool_used_bytes
(There is no such thing as jvm_memory_pool_bytes_used
in client_java)jvm_memory_pool_allocated_bytes_total
(There is no such thing as jvm_memory_pool_allocated_bytes_created
in client_java)jvm_memory_pool_committed_bytes
(There is no such thing as jvm_memory_pool_bytes_committed
in client_java )jvm_memory_pool_init_bytes
(There is no such thing asjvm_memory_pool_bytes_init
in client_java)jvm_memory_pool_max_bytes
(There is no such thing asjvm_memory_pool_bytes_max
in client_java)jvm_memory_pool_bytes_used
in client_java)jvm_memory_pool_collection_committed_bytes
jvm_memory_pool_collection_init_bytes
jvm_memory_pool_collection_max_bytes
jvm_memory_pool_collection_used_bytes
jvm_threads_deadlocked
jvm_threads_deadlocked_monitor
jvm_threads_peak
jvm_threads_started_total
jvm_threads_state
All those metrics are still available when using the httpserver but under a different name that matches the JMX MBean where the actual value is.
For example, the equivalent to jvm_classes_loaded
/ jvm_classes_loaded_total
in javagent is java_lang_ClassLoading_LoadedClassCount
.
And the equivalent to jvm_threads_current
in httpserver is java_lang_Threading_ThreadCount
.
Here is a table with some equivalences
jmxexporter javaagent | jmxexporter httpserver | JMX MBean | notes |
---|---|---|---|
jvm_classes_loaded | java_lang_ClassLoading_LoadedClassCount | java.lang:name=null,type=ClassLoading,attribute=LoadedClassCount | link |
jvm_classes_loaded_total | java_lang_ClassLoading_TotalLoadedClassCount | java.lang:name=null,type=ClassLoading,attribute=TotalLoadedClassCount | link |
jvm_threads_current | java_lang_Threading_ThreadCount | java.lang:name=null,type=Threading,attribute=ThreadCount | link |
jvm_threads_daemon | java_lang_Threading_DaemonThreadCount | java.lang:name=null,type=Threading,attribute=DaemonThreadCount | link |
jvm_memory_used_bytes | java_lang_Memory_HeapMemoryUsage_used | java.lang:name=null,type=Memory,attribute=used | link |
jvm_memory_pool_committed_bytes | java_lang_G1_Survivor_Space_Usage_committed | java.lang:name=G1 Survivor Space,type=MemoryPool,attribute=committed | link |
jvm_memory_pool_init_bytes | java_lang_G1_Survivor_Space_Usage_init | java.lang:name=G1 Survivor Space,type=MemoryPool,attribute=init | link |
jvm_memory_pool_max_bytes | java_lang_G1_Survivor_Space_Usage_max | java.lang:name=G1 Survivor Space,type=MemoryPool,attribute=max | link |
jvm_memory_pool_used_bytes | java_lang_G1_Survivor_Space_Usage_used | java.lang:name=G1 Survivor Space,type=MemoryPool,attribute=used | link |
jvm_threads_deadlocked | no equivalent | java.lang:type=Threading,method=findDeadlockedThreads | link jmxexporter uses client_java JvmMetrics / JvmThreadsMetrics which uses the findDeadlockedThreads() method in the MBean (not an attribute) |
jvm_threads_deadlocked_monitor | no equivalent | java.lang:type=Threading,method=findMonitorDeadlockedThreads | link jmxexporter uses client_java JvmMetrics / JvmThreadsMetrics which uses the findMonitorDeadlockedThreads() method in the MBean (not an attribute) |
jvm_threads_peak | java_lang_Threading_PeakThreadCount | java.lang:name=null,type=Threading,attribute=PeakThreadCount | link |
jvm_threads_started_total | java_lang_Threading_TotalStartedThreadCount | java.lang:name=null,type=Threading,attribute=TotalStartedThreadCount | link |
jvm_threads_state | no equivalent | java.lang:type=Threading | link there is no MBean equivalent this is computed from java.lang:type=Threading getAllThreadIds() and getThreadInfo() |