Page 1 of 1 1
Topic Options
#115853 - 2004-03-10 06:49 PM Kixtart/WMI Performance Monitoring
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
Using Kixtart 4.22 on an XP test machine, going off of information from here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting11182003.asp
Trying to create a Kixtart/WMI processor performance monitor, here's the Code:
 $strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * From Win32_PerfRawData_PerfOS_Processor Where Name = '0'")
For Each $objItem in $colItems
$CounterValue1 = $objItem.PercentUserTime
$TimeValue1 = $objItem.TimeStamp_Sys100NS
Next
For $i = 1 to 5
Sleep 1
$colItems = $objWMIService.ExecQuery("Select * From Win32_PerfRawData_PerfOS_Processor Where Name = '0'")
For Each $objItem in $colItems
$CounterValue2 = $objItem.PercentUserTime
$TimeValue2 = $objItem.TimeStamp_Sys100NS
If $TimeValue2 - $TimeValue1 = 0
? "Percent User Time = 0%"
Else
$PercentProcessorTime = 100 * ($CounterValue2 - $CounterValue1) / ($TimeValue2 - $TimeValue1)
? "Percent User Time = " + $PercentProcessorTime + "%"
Endif
$CounterValue1 = $CounterValue2
$TimeValue1 = $TimeValue2
Next
Next


Keep getting an "ERROR : Error in experssion.!" on the line that has "If $TimeValue2 - $TimeValue1 = 0" on it.
I put a "? $TimeValue1" and "? $TimeValue2" line in after each of those variables to see what they were returning. I got 4230585452000 for $TimeValue1 and 4230595588000 for $TimeValue2. Set up a seperate script to see if it just didn't like the math on those numbers... had no problem with it, it just doesn't want to work when it gets the numbers from a WMI query.

Any ideas?

Top
#115854 - 2004-03-10 07:03 PM Re: Kixtart/WMI Performance Monitoring
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I believe that property is returning a string. Try casting it with cdbl() and see if it works
_________________________
Eric

Top
#115855 - 2004-03-10 07:13 PM Re: Kixtart/WMI Performance Monitoring
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
I may not be doing it right, but now it gives an error on the CDbl($TimeValue2 - $TimeValue1) line. ERROR : Error in expression.!
Top
#115856 - 2004-03-10 07:23 PM Re: Kixtart/WMI Performance Monitoring
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You were told to cast the variables as CDBL() not the result!
The code below works for me.
Code:

$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * From Win32_PerfRawData_PerfOS_Processor Where Name = '0'")
For Each $objItem in $colItems
$CounterValue1 = cdbl($objItem.PercentUserTime)
$TimeValue1 = cdbl($objItem.TimeStamp_Sys100NS)
Next
For $i = 1 to 5
Sleep 1
$colItems = $objWMIService.ExecQuery("Select * From Win32_PerfRawData_PerfOS_Processor Where Name = '0'")
For Each $objItem in $colItems
$CounterValue2 = cdbl($objItem.PercentUserTime)
$TimeValue2 = cdbl($objItem.TimeStamp_Sys100NS)
If $TimeValue2 = $TimeValue1
? "Percent User Time = 0%"
Else
$PercentProcessorTime = 100 * ($CounterValue2 - $CounterValue1) / ($TimeValue2 - $TimeValue1)
? "Percent User Time = " + $PercentProcessorTime + "%"
Endif
$CounterValue1 = $CounterValue2
$TimeValue1 = $TimeValue2
Next
Next


_________________________
There are two types of vessels, submarines and targets.

Top
#115857 - 2004-03-10 07:23 PM Re: Kixtart/WMI Performance Monitoring
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
That's not going to work because it will just try to evaluate what's in the () first. So try something like this

Code:

If cdbl($TimeValue2) - cdbl($TimeValue1) = 0

_________________________
Eric

Top
#115858 - 2004-03-10 10:11 PM Re: Kixtart/WMI Performance Monitoring
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
Sweet, Jens's code works. Thanks.
Top
#115859 - 2004-03-11 12:05 AM Re: Kixtart/WMI Performance Monitoring
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I've played around a little with monitoring processes with WMI. Check out KiXforms: ProcessMon for some ideas.
Top
#115860 - 2004-03-11 06:12 PM Re: Kixtart/WMI Performance Monitoring
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
Very nice Chris. It seems to have 100% usage and 0% usage mixed up though. I ran your Kixform Monitoring tool against a remote server that has very little to do ever, it shows a constant 100%. I ran the script I just wrote against it, it shows 0% to 1%. I went over to the server, and loaded task manager, and it shows 0% to 1%.

Ran it against a different server, one that normally has constant flucuations in CPU usage, it shows those flucuations, however when it goes back down to 0% here and there, your Kixform shows 100% instead of 0%.

You know what would be really cool? Something like your kixform that can monitor more than one computer at a time. These WMI performance monitor scripts are much more effecient than any performance monitoring application once you get them working right.

Top
#115861 - 2004-03-11 07:21 PM Re: Kixtart/WMI Performance Monitoring
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
If you're monitoring the System Idle Process it will show close to 100% (depending on what you're doing, of course), as technically that is the CPU utilization of that process.

Monitor iexplore.exe instead and watch how even moving the mouse over the window uses CPU cycles.

Top
#115862 - 2004-03-11 09:27 PM Re: Kixtart/WMI Performance Monitoring
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
Ahh, you know, I wasn't even selecting a process to monitor, I was just clicking monitor when it came up.

Too much math involved in this perfmance monitoring stuff.

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 874 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.062 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org