WMI and Time processor for a process - Part 2
WMI and Time processor for a process - Part 2
Hi all,
I'm currently looking for a solution to monitor process with the same name (xxx.exe) and there CPU consomation.
I have already post my question but find no answer, my answer is the following (I will try to explain it differently), I would like to know at regular interval the list of process that consume for example more than 15 % of the CPU time in order to kill them.
Thanks for your detailled help, I have already look at the documentation and find no solution. I try the WMI witch seams to do this but since I'm not an expert, I get what I want.
Thanks for your help at advance.
Alan (France).
I'm currently looking for a solution to monitor process with the same name (xxx.exe) and there CPU consomation.
I have already post my question but find no answer, my answer is the following (I will try to explain it differently), I would like to know at regular interval the list of process that consume for example more than 15 % of the CPU time in order to kill them.
Thanks for your detailled help, I have already look at the documentation and find no solution. I try the WMI witch seams to do this but since I'm not an expert, I get what I want.
Thanks for your help at advance.
Alan (France).
Knowing that I have a Windows 2000 Server (and not XP), I can used this (with WMI) :
Select IDProcess, Name,PercentProcessorTime from Win32_PerfRawData_PerfProc_Process where name='xxxx'
The only problem is that ON WINDOWS 2000 the PercentProcessorTime represent the % of the CPU used but not human reading. For example I would like to generate an alert when the CPU reach > 20 % and the value return doesn't correspond to anything.
Any idea ?
Select IDProcess, Name,PercentProcessorTime from Win32_PerfRawData_PerfProc_Process where name='xxxx'
The only problem is that ON WINDOWS 2000 the PercentProcessorTime represent the % of the CPU used but not human reading. For example I would like to generate an alert when the CPU reach > 20 % and the value return doesn't correspond to anything.
Any idea ?
I have found finally the correct script , but I don't know how I can integrate to HM since it used : wscript object, any help will be VERY appreciate. I'm sure it will interessted many of us too
or I hope.
Alan
'Get % Processor Time for a process
' after the script is started, launch Task Manager to see the result
' process name to monitor
sProcessName = "taskmgr"
'Connect to Local Machine
set wmi_service = _
GetObject("winmgmts:{impersonationlevel=impersonate}!\root\cimv2")
sObjectPath = "Win32_PerfRawData_PerfProc_Process.Name=" _
& chr(34) & sProcessName & chr(34)
wscript.echo "Monitoring " & sObjectPath
set perf_instance1 = wmi_service.get( sObjectPath )
N1 = perf_instance1.PercentProcessorTime
D1 = perf_instance1.TimeStamp_Sys100NS
do
'Sleep for one second = 1000 ms
wscript.sleep(1000)
set perf_instance2 = wmi_service.get( sObjectPath )
N2 = perf_instance2.PercentProcessorTime
D2 = perf_instance2.TimeStamp_Sys100NS
' CounterType - PERF_100NSEC_TIMER
' Formula = ((N2 - N1) / (D2 - D1)) x 100
if ( 0 = (D2-D1) ) then
wscript.echo "divide by zero"
else
PercentProcessorTime = ((N2 - N1) / (D2 - D1)) * 100
wscript.echo "% Processor Time = " , PercentProcessorTime
end if
N1 = N2
D1 = D2
'looping for 30 seconds
i = i + 1
loop until i = 30
WScript.Echo "Finished"

Alan
'Get % Processor Time for a process
' after the script is started, launch Task Manager to see the result
' process name to monitor
sProcessName = "taskmgr"
'Connect to Local Machine
set wmi_service = _
GetObject("winmgmts:{impersonationlevel=impersonate}!\root\cimv2")
sObjectPath = "Win32_PerfRawData_PerfProc_Process.Name=" _
& chr(34) & sProcessName & chr(34)
wscript.echo "Monitoring " & sObjectPath
set perf_instance1 = wmi_service.get( sObjectPath )
N1 = perf_instance1.PercentProcessorTime
D1 = perf_instance1.TimeStamp_Sys100NS
do
'Sleep for one second = 1000 ms
wscript.sleep(1000)
set perf_instance2 = wmi_service.get( sObjectPath )
N2 = perf_instance2.PercentProcessorTime
D2 = perf_instance2.TimeStamp_Sys100NS
' CounterType - PERF_100NSEC_TIMER
' Formula = ((N2 - N1) / (D2 - D1)) x 100
if ( 0 = (D2-D1) ) then
wscript.echo "divide by zero"
else
PercentProcessorTime = ((N2 - N1) / (D2 - D1)) * 100
wscript.echo "% Processor Time = " , PercentProcessorTime
end if
N1 = N2
D1 = D2
'looping for 30 seconds
i = i + 1
loop until i = 30
WScript.Echo "Finished"
Yes, It's a promlem.
So, I think, you should adjust your script according to HM scripts requirements (http://www.ks-soft.net/hostmon.eng/tests.htm#script) and create Active Script Test.
Regards,
Yoorix
So, I think, you should adjust your script according to HM scripts requirements (http://www.ks-soft.net/hostmon.eng/tests.htm#script) and create Active Script Test.
Regards,
Yoorix
I think I already answered this questionbut I don't know how I can integrate to HM since it used
==========
If you want to use script with HostMonitor, please follow certain rules. Rules described in the manual.
Active scripts: http://www.ks-soft.net/hostmon.eng/mfra ... htm#script
Shell script: http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
==========
Regards
Alex