Got CPU Load incorrectly using script

  • Thread starter Yu Haitao David
  • Start date
Y

Yu Haitao David

Hi,

I got my CPU load value of 100% whatever it really was in taskmgr.

I tried using "Win32_Processor.LoadPercentage" and
"Win32_PerfFormattedData_PerfOS_Processor_PercentProcessorTime", always
100%, while actually the load was below 20%.

But the script works normally under win2k.

My PC has winxp-sp1, and the script like the followings:

'=================================
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)

For Each objItem in colItems
WScript.Echo "LoadPercentage: " & objItem.LoadPercentage
Next
 
Y

Yu Haitao David

I got this problem clearly after I install my .NET Framework 1.1 SP1:

I have two scripts to check the CPU load and Memory usage, and I need to run
them one by one to generate data for MRTG. After testing, I found this:

1. Run checkcpu.vbs first, it returns normal value, 5% for example. There
appears a process named: wmiprvse.exe
2. Run checkmem.vbs then, it gets error: 80041010

if I kill the process wmiprvse.exe that appeared when doing step 1, I change
the order of these two scripts:

1. Run checkmem.vbs first, it returns normally, another wmiprvse.exe appears
2. Run checkcpu.vbs then, it runs longer, and return 100% which is incorrect

anyone can help me on this?
 
J

Jim Vierra

FYI - I ran your exact script on XPSP2 with NET 1.1 SP1 and NET 2.0
Installed. Get 7% or less most of the time. Since this is an instantaneous
value it probably not much good. You need to use one of the "cooked"
counters to get an average that is meaningful.

I am not sure which is which but I am sure it is documented. Some counters
are for the system while the app is running and others are agnostic. I
would read the SDK documentation very carefully to see which counter you
really want and how to use it.
 
Y

Yu Haitao David

thanks for your reply, but it is about two scripts. Only one script, it
returns normal value (or appears resonable).

but if run another after one, checkcpu.vbs first, checkmem.vbs got error
80041010 (but run chekmem.vbs only won't get error );

if checkmem.vbs first, checkcpu.vbs will not get error, but got unresonable
value of 100% all the time.

the scripts are very simple, so I think


'============checkcpu.vbs===============
strComputer = "."
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set wbemObjectSet = objWMIService.ExecQuery("Select * from
Win32_Processor",,48)
For Each wbemObject In wbemObjectSet
wscript.echo wbemObject.LoadPercentage
next
wscript.echo "0"
wscript.echo ""
wscript.echo ""
,=================end=====================

'============checkmem.vbs================
strComputer = "."
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set wbemObjectSet = objWMIService.ExecQuery("select * from
Win32_PerfFormattedData_PerfOS_Memory")
For Each wbemObject In wbemObjectSet
wscript.echo wbemObject.PercentCommittedBytesInUse
next
wscript.echo "0"
wscript.echo ""
wscript.echo ""
,=======================================
 
J

Jim Vierra

This works just fine for me: Same scripts just throw out the extra garbage
add a couple of labels.

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& strComputer & "\root\cimv2")
Set wbemObjectSet = objWMIService.ExecQuery("Select * from
Win32_Processor",,48)
For Each wbemObject In wbemObjectSet
wscript.echo "Load:" & wbemObject.LoadPercentage
next

Set wbemObjectSet = objWMIService.ExecQuery("select * from
Win32_PerfFormattedData_PerfOS_Memory")
For Each wbemObject In wbemObjectSet
wscript.echo "CommitedBytes:" & wbemObject.PercentCommittedBytesInUse
next
 
Y

Yu Haitao David

We got the same point to make it work :D

the reason for this problem is CANNOT GetObject twice, even in different
scripts.

But I need to seperate the codes into different scripts to satisfy graphing
more pictures in MRTG.

:(
 
Y

Yu Haitao David

I got this fixed by installing winxp sp2...



Yu Haitao David said:
We got the same point to make it work :D

the reason for this problem is CANNOT GetObject twice, even in different
scripts.

But I need to seperate the codes into different scripts to satisfy
graphing
more pictures in MRTG.

:(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top