I want to collect Operating Systems Parameters..in my mbean so that after registering it i can see those values on JConsole..I have collected some parameters but I cant collect the values for ProcessCpuTime,SystemCpuLoad I tried it with OperatingSystemMXBean interface object but it doesn't work. Also i read on google that those method needs APIs which are not supported on Windows.So is there another way to calculate those values mathematically...Please help me
Asked
Active
Viewed 1,471 times
1 Answers
0
The Windows JVM implementation of java.lang.management.OperatingSystemMXBean is com.sun.management.OperatingSystem. You can reference it directly by casting the former:
import java.lang.management.*;
import com.sun.management.*;
...
OperatingSystem os = (OperatingSystem)ManagementFactory.getOperatingSystemMXBean();
There's some variability between the Java 6 and java 7 versions of this class, which can be observed with this Groovy script:
import java.lang.management.*;
os = ManagementFactory.getOperatingSystemMXBean();
println os.getClass().getName();
try { println "Process CPU Load:${os.getProcessCpuLoad()}"; } catch (e) {}
try { println "Process CPU Time:${os.getProcessCpuTime()}"; } catch (e) {}
try { println "System CPU Load:${os.getSystemCpuLoad()}"; } catch (e) {}
Java 6 Output:
com.sun.management.OperatingSystem
Process CPU Time:79810111600
Java 7 Output:
com.sun.management.OperatingSystem
Process CPU Load:-1.0
Process CPU Time:1840811800
System CPU Load:0.4902940980431365
So it's not as useful as the Linux [et.al.] variant, but you might get what you're looking for.

Nicholas
- 15,916
- 4
- 42
- 66