I am glad to introduce you my solution to monitor CPU usage (%) for certain process using HostMonitor. The VB script below uses WMI and is designed for "Shell Script" test method: http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
Of course it is possible to use "Performance Counter" test method to do the same, but I think (and KS-Soft suggests ) that WMI technology is much more reliable.
There are three parameters required for the script: <Computername>, <ProcessName>, <MaxLimit>
E.g.: MySuperServer winamp 50
If script will check local host, you may specify dot (".") instead of computer's name, e.g.: . winamp 50
Start cmd: cmd /c cscript /B /E:VBScript %Script% %Params%
Script:
Code: Select all
Option Explicit
const statusAlive = "scriptRes:Host is alive:"
const statusDead = "scriptRes:No answer:"
const statusUnknown = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"
dim objArgs, strComputer, strProcess, maxLimit, objWMIService, processProp, process, N1, D1,PercentProcessorTime, i
Set objArgs = WScript.Arguments
if objArgs.Count <> 3 then
WScript.StdOut.Write( statusUnknown & "Parameters are required: <Computername>, <ProcessName>, <MaxLimit>" )
else
strComputer = objArgs(0)
strProcess = objArgs(1)
maxLimit = objArgs(2)
'WScript.StdOut.Write( strComputer & " " & strProcess & " " & maxLimit)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
N1 = 0
D1 = 0
For i = 1 To 2
Set processProp = objWMIService.ExecQuery("select IdProcess, Name, PercentProcessorTime,TimeStamp_Sys100NS from Win32_PerfRawData_PerfProc_Process WHERE Name = '" & strProcess & "'")
For Each process in processProp
N1 = process.PercentProcessorTime - N1
D1 = process.TimeStamp_Sys100NS - D1
Next
wscript.sleep(1000)
next
PercentProcessorTime = Round((N1 / D1) * 100)
if PercentProcessorTime > Round(maxLimit) then
WScript.StdOut.Write( statusBad & PercentProcessorTime & " %" )
else
WScript.StdOut.Write( statusOk & PercentProcessorTime & " %" )
end if
End If
------------------
Yoorix