We would like to internalize some of the functionality of JConsole/JVisualVM and gather data about cpu-utilization and memory consumption from within the running application. The reason is, that security-constraints prevent us from opening the jmx ports to the outside on a production system.
Most of the data required can be monitored via the MXBeans, however, the cputime used for garbage-collection still eludes us. Monitoring the gc-time via the GarbageCollectorMXBean
is not useful, as it only provides walltime of the parallel working collectors.
I assume it would be possible to use the ThreadMXBean to determine the cputime of all gc-threads. I can see no way to securely identify those threads.
Does anyone know, how JVisualVM calculates that number?
Some time ago I have written summary about JVM diagnostics API, it is available here.
In short, MBean and "pref counters" are main source of JVM self diagnostic.
JVisualVM is using GarbageCollectorMXBean
interpreting wall clock time as CPU time (i.e. showing nonsense).
ThreadMXBean
does not include GC thread is thread list so it is useless too. In SJK tool I was subtracting cumulative CPU time of all application thread from process CPU time. This approach is not accurate, but better than nothing.
"Perf counters" have accurate information about CPU usage for GC. "Perf counters" could be accessed via sun.management.counter.perf.PerfInstrumentation
.
Here you can find example (JUnit test) dumping "perf counters" of host JVM.
You need sun.gc.collector.0.time
and sun.gc.collector.1.time
counters which measure cummulative CPU usage for young and old / full GC (take a note that they reported in ticks).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With