prometheus / client_java

Prometheus instrumentation library for JVM applications
http://prometheus.github.io/client_java/
Apache License 2.0
2.15k stars 781 forks source link

Would it make sense to add to Default exporters JVM's Safepoint metrics? #576

Open mr-git opened 3 years ago

mr-git commented 3 years ago

Would it make sense to add to Default exporters JVM's Safepoint metrics?

HotspotRuntimeMBean exposes:

In applications with many threads and long computations, these metrics can manifest how much time is spent before GC to get all threads to Safepoint and pause it.

brian-brazil commented 3 years ago

This sounds reasonable to add, though we'd need to check that they work on the various JVM implementations.

darkl0rd commented 2 years ago

Any idea when this functionality is going to be added? In the interim, is there a way to manually add these to the JMX exporter?

dhoard commented 1 year ago

I have some test code that calls sun.management.HotspotRuntimeMBean via reflection and support is not great.

For Java 6 OpenJDK-based VMs...

For Java 8 OpenJDK-based VMs...

For Java 11 OpenJDK-based VMs...

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.prometheus.jmx.collector.HotSpotCollector (file:/temp/jmx_prometheus_javaagent.jar) to method sun.management.ManagementFactoryHelper.getHotspotRuntimeMBean()
WARNING: Please consider reporting this to the maintainers of io.prometheus.jmx.collector.HotSpotCollector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

For Java 17 OpenJDK-based VMs...

java.lang.IllegalAccessException: class io.prometheus.jmx.collector.HotSpotCollector cannot access class sun.management.ManagementFactoryHelper (in module java.management) because module java.management does not export sun.management to unnamed module @7cf10a6f
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
    at java.base/java.lang.reflect.Method.invoke(Method.java:560)
    at io.prometheus.jmx.collector.HotSpotCollector.accessHotspotRuntimeMBean(HotSpotCollector.java:68)
    at io.prometheus.jmx.collector.HotSpotCollector.<init>(HotSpotCollector.java:48)
    at io.prometheus.jmx.exporter.Exporter.registerDefaultExports(Exporter.java:266)
    at io.prometheus.jmx.exporter.Exporter.start(Exporter.java:132)
    at io.prometheus.jmx.JavaAgent.premain(JavaAgent.java:50)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:491)
    at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:503)

For non OpenJDK-based VMs (IBM)