Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternate of getSystemLoadAverage() for Windows?

I am working on with some code to monitor Cpu load using Java. I am using following code in my app to get system load

public static double getCPULoad() {
    OperatingSystemMXBean osMBean
                = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

    double load = osMBean.getSystemLoadAverage();
    return load;
}

But on windows it returns me a negative value (-1.0). Is there any way i can solve this problem?

like image 527
Navdeep Singh Avatar asked Nov 11 '14 18:11

Navdeep Singh


People also ask

How do you find load average in Windows?

The key to calculating a load averages on Windows is the ability to monitor the depth of the processor queue. The Microsoft article, Observing Processor Queue Length, describes the Windows System\Processor Queue Length metric, the critical measurement that allows the Host sFlow agent to calculate load averages.

How do I simulate high CPU usage Windows?

CpuStres is a utility that can be used to simulate CPU activity by running up to 64 threads in a tight loop.

What is the difference between load average and CPU utilization?

System load/CPU Load – is a measurement of CPU over or under-utilization in a Linux system; the number of processes which are being executed by the CPU or in waiting state. Load average – is the average system load calculated over a given period of time of 1, 5 and 15 minutes.


1 Answers

Please read this blog. It's not an official solution but when using com.sun.management.OperatingSystemMXBean instead of java.lang.management.OperatingSystemMXBean there are two methods getSystemCpuLoad() and getProcessCpuLoad() that are working.

like image 84
Uli Avatar answered Oct 19 '22 15:10

Uli