tags:

views:

207

answers:

5

Is there a way in monitoring cpu usage using purely java language? if yes, can you please share some articles regarding this topic. thank you.

+1  A: 

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

kgiannakakis
+1  A: 

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 :?

strainer
This is a reasonable idea. You'll have to use proper microbenchmark tricks though (run for some length of time, warm up all loops before timing, use `System.nanoTime()`). There will still be a fair bit of flutter in performance too over the timing interval.
BobMcGee
+3  A: 

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.

strainer
A: 

How about using jmx mbeans?

final OperatingSystemMXBean osbean = 
            ManagementFactory.getOperatingSystemMXBean();
double load = myOsBean.getSystemLoadAverage();
baskin
A: 

thanks for the help, i really appreciate it.

shamkovich