WMI Request - CPU LoadPercentage

I am looking for the best way to get the CPU load in percent with WMI from several systems (these are different processors, etc.). My code works, but I think there is a better way to get around all CPU usage in percent.

Any ideas?

Thank you in advance!

SelectQuery queryCpuUsage = new SelectQuery("SELECT * FROM Win32_Processor"); ManagementObjectSearcher cpuUsage = new ManagementObjectSearcher(scope, queryCpuUsage); ManagementObjectCollection cpuUsageCollection = cpuUsage.Get(); foreach (ManagementObject queryObj in cpuUsageCollection) { iCPU++; calcCPU = Convert.ToInt32(queryObj["LoadPercentage"]); perCPU = perCPU + calcCPU; } perCPU = perCPU / iCPU; cpuUsageCollection.Dispose(); Console.WriteLine("LoadPercentage CPU: {0}", perCPU); 
+6
source share
1 answer

Personally, I would go for the Win32_PerfRawData_PerfOS_Processor class, because it is much more accurate. You will need to request both PercentProcessorTime and TimeStamp_Sys100NS . Here you can find the exact formula.

+4
source

Source: https://habr.com/ru/post/910147/


All Articles