|
|
Hi,
I'm trying to use WMI to calculate cpu usage. I'm running the following script into a W2K3 box. It works fine, but I had some doubts about the values that I receive.
Reading MSDN (http://msdn2.microsoft.com/En-US/library/aa394271.aspx), it tells that PercentProcessorTime "This property was designed as a primary indicator of processor activity". Ok, but I want to break it into user time and system time.
So, I think that I must use PercentUserTime, PercentPrivilegedTime and PercentIdleTime. If I sum this 3 values, I should get 100%.
The problem is that almost never the sum is equals to 100. I understand that we can have some round problems. But I was expecting to see 99, 100 or 101. When the server is busy, often I receive 103. If it isn't so busy, sometimes I receive 98...
Am I being grumpy?
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE name='_Total'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems WScript.Echo "PercentIdleTime: " & objItem.PercentIdleTime WScript.Echo "PercentInterruptTime: " & objItem.PercentInterruptTime WScript.Echo "PercentPrivilegedTime: " & objItem.PercentPrivilegedTime WScript.Echo "PercentProcessorTime: " & objItem.PercentProcessorTime WScript.Echo "PercentUserTime: " & objItem.PercentUserTime Next
|
|
|