On a (or any?) server there are several processes running as svchost.exe with parameters.
Is it possible to monitor cpu usage for a specific one?
Thanks!
CPU usage specific svchost instance
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
There is no standard test for monitoring specific process CPU usage.
You may use Shell Script test with costom made script what uses WMI.
E.g. VB script may look like the following:
Start CMD: cmd /c cscript /B /E:VBScript %Script% %Params%
Script requires 5 parameters: <IP/hostname> <Login Username> <Login Password> <Process full path> <CPU usage threshold>
E.g.:
10.10.0.100 Admin MyPassword "C:\Windows\system32\svchost.exe -k RPCSS" 30
Please note, this script uses WMI and checks CommandLine parameter of Win32_Process object. This parameter may be empty if non-administrator account is used for connection.
You may use Shell Script test with costom made script what uses WMI.
E.g. VB script may look like the following:
Code: Select all
On Error Resume Next
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 i, objArgs, strComputer, strUser, strPsw, strProcess, objSWbemLocator, objWMI, colList, objItem, processID, CPUusage, threshold
Set objArgs = WScript.Arguments
If objArgs.Count <> 5 Then
WScript.StdOut.Write statusUnknown & "Required parameters: <IP/hostname> <Login Username> <Login Password> <Process full path> <CPU usage threshold>"
WScript.Quit
End If
strComputer = objArgs(0)
strUser = objArgs(1)
strPsw = objArgs(2)
strProcess = objArgs(3)
strProcess = Replace(strProcess,"\","\\")
threshold = int(objArgs(4))
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
If Err.Number <> 0 Then
WScript.StdOut.Write statusUnknown & Err.Description
WScript.Quit
End If
Set objWMI = objSWbemLocator.ConnectServer _
(strComputer, "root\cimv2", strUser, strPsw)
If Err.Number <> 0 Then
WScript.StdOut.Write statusUnknown & Err.Description
WScript.Quit
End If
Set colList = objWMI.ExecQuery("SELECT ProcessId, CommandLine FROM Win32_Process WHERE CommandLine='" & strProcess & "'")
If colList.count = 0 Then
WScript.StdOut.Write statusUnknown & "process not found: " & strProcess
WScript.Quit
End If
For Each objItem in colList
processID = objItem.ProcessId
Next
If Err.Number <> 0 Then
WScript.StdOut.Write statusUnknown & Err.Description
WScript.Quit
End If
Set colList = objWMI.ExecQuery("SELECT IDProcess, PercentProcessorTime from Win32_PerfFormattedData_PerfProc_Process WHERE IDProcess=" & processID)
For Each objItem in colList
CPUusage = int(objItem.PercentProcessorTime)
Next
If Err.Number <> 0 Then
WScript.StdOut.Write statusUnknown & Err.Description
WScript.Quit
End If
if CPUusage > threshold Then
WScript.StdOut.Write statusBad & CPUusage
else
WScript.StdOut.Write statusOk & CPUusage
End If
Script requires 5 parameters: <IP/hostname> <Login Username> <Login Password> <Process full path> <CPU usage threshold>
E.g.:
10.10.0.100 Admin MyPassword "C:\Windows\system32\svchost.exe -k RPCSS" 30
Please note, this script uses WMI and checks CommandLine parameter of Win32_Process object. This parameter may be empty if non-administrator account is used for connection.
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact: