Monitoring Java Safepoint Time in JDK16+
Carter Kozak
ckozak at ckozak.net
Wed Jun 16 19:12:26 UTC 2021
As java 16 and beyond lock down access to internal components by default, it can be difficult to produce Prometheus-style metrics describing application safepoints. I’ve been monitoring these metrics so that I can be alerted when an application spends more than ~10% of time in safepoints for some duration, because it means that something has gone wrong: Most often GC spirals, however excessive thread dumps, deadlock checks, etc can contribute. This has been one of the most meaningful tools in my arsenal to detect general JVM badness, however there doesn’t seem to be a way to access the data in newer JREs without allowing access to internal components.
Previously I was able to use something along these lines, which required legacy sun.management component access.
sun.management.HotspotRuntimeMBean hotspotRuntimeManagementBean = sun.management.ManagementFactoryHelper.getHotspotRuntimeMBean();
long totalSafepointTimeMillis = hotspotRuntimeManagementBean.getTotalSafepointTime();
Before I get ahead of myself, I’d like to confirm that I haven’t missed a supported pathway to access safepoint time. If my read is correct and there’s no way to access this information from inside the running JVM, would it be a a reasonable addition to the public API?
Thanks,
Carter Kozak
More information about the serviceability-dev
mailing list