WMI and Time processor for a process - Part 2

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
a.falanga
Posts: 9
Joined: Mon Mar 06, 2006 6:18 am

WMI and Time processor for a process - Part 2

Post by a.falanga »

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).
a.falanga
Posts: 9
Joined: Mon Mar 06, 2006 6:18 am

Post by a.falanga »

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 ?
a.falanga
Posts: 9
Joined: Mon Mar 06, 2006 6:18 am

Post by a.falanga »

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"
Yoorix
Posts: 177
Joined: Wed Dec 14, 2005 8:28 am

Post by Yoorix »

Try to use
"Select IDProcess, Name,PercentProcessorTime from Win32_PerfFormattedData_PerfProc_Process where name='xxxx'" instead.

Regards,
Yoorix
a.falanga
Posts: 9
Joined: Mon Mar 06, 2006 6:18 am

Post by a.falanga »

Hi Yoorix,

Win32_PerfFormattedData_PerfProc_Process doesn't exists on Windows 2000 that here my problem !!!!

Alain
Yoorix
Posts: 177
Joined: Wed Dec 14, 2005 8:28 am

Post by Yoorix »

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
a.falanga
Posts: 9
Joined: Mon Mar 06, 2006 6:18 am

Post by a.falanga »

That why I have post, because I need help on converting script.

Alan
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

but I don't know how I can integrate to HM since it used
I think I already answered this question
==========
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
a.falanga
Posts: 9
Joined: Mon Mar 06, 2006 6:18 am

Post by a.falanga »

Alex,

That I need is to convert this script to run as active script and not any other test.
I know where put the script, but I get error when using with HM, that I don't understand.
If you can help me on this it will be a great advance for me.

Regards,
Alan
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Could you please read the manual? It describes how script should look.
If you do not understand something, please say what exactly you do not understand
If you see some error, please say what exactly error do you see.

Regards
Alex
Post Reply