Is there a way to measure CPU usage of the JVM (once a java application is started) cross platform (windows + unix + mac)? I have used Jconsole but what I need is a java code that does this, and not a tool through which I can monitor CPU utilization. I have tried out
ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage()
using JMX, but it doesn't help since what I need is the specific CPU usage by the JVM (say when I start a server), not the system load average.
You can try to use https://github.com/mvysny/webmon . You just add the webmon-analyzer jar to your project and you'll start the sampler and TCP/IP server. The sampler will poll JMX API and will keep the stats for awhile, you can then simply telnet localhost 5455
to get a text dump of those stats. Awesome for production. Disclaimer: I'm the author, and the project is old-ish.
At any given instant, a thread is either running (100% of core) or not (0%). There is no in-between. What you need is a short-term series of snapshots of the thread's running state, and average it over those.
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