java cpu usage monitoring

Viewed 34528

Is there a way in monitoring CPU usage using pure Java?

6 Answers

There is a gem in the comments on the article which kgiannakakis linked:

javasysmon

JavaSysMon manages processes and reports useful system performance metrics cross-platform. You can think of it as a cross-platform version of the UNIX `top’ command, along with the ability to kill processes. It comes in the form of a single JAR file /..

-works on Windows, Mac OS X, Linux, and Solaris.

How about using jmx mbeans?

final OperatingSystemMXBean myOsBean= 
            ManagementFactory.getOperatingSystemMXBean();
double load = myOsBean.getSystemLoadAverage();

This is not possible using pure Java. See this article for some ideas.

Maybe if stuck, you might 'sense' cpu availability by running an intermittent bogomips calculator in a background thread, and smoothing and normalising its findings. ...worth a shot no :?

if you are using linux - just use jconsole - you will get all the track of java memory management

Related