It would be nice to know when the CPU was running high. However, it is not uncommon for it to spike to even 100% now and then and we don’t want a bunch of false alarms. Instead, I would rather know the CPU was running say above 80% for over a 1 minute straight (or 5 checks that are 15 seconds apart).
I do this by using a simple batch file and the an Alert Counter in Windows Performance Monitor.
Create a directory named CPU (C:CPU) Make a batch file (cpu.bat) with the following code.
CODE
for /f "tokens=*" %%a in ('now') do set timestamp=%%a
if %~1 GTR 80 goto :alarm
echo 0 >c:CPUoutfile.txt
set timestamp=
goto :eof
:alarm
echo 1 >>c:CPUoutfile.txt
for /f %%a in ('type c:CPUoutfile.txt^|find /c "1"') do set count=%%a
if %count% gtr 5 call c:CPUalert.bat
set timestamp=
if %~1 GTR 80 goto :alarm
echo 0 >c:CPUoutfile.txt
set timestamp=
goto :eof
:alarm
echo 1 >>c:CPUoutfile.txt
for /f %%a in ('type c:CPUoutfile.txt^|find /c "1"') do set count=%%a
if %count% gtr 5 call c:CPUalert.bat
set timestamp=
Then open the Performance Monitor and go to “Alerts” and add an alert for the CPU processor. The key item on this page is to set it to alert if the value if over 0 (zero). (We need an alert on every check as the real check if done by the batch file.) I set it to run every 15 seconds.
On the Action Tab, set the alert monitor to run our batch file on an alert. Open up the Command Line Arguments to only display the Measured Value.
Set the Schedule to run all the time.
There are only 3 things to modify in the batch file.
On this line if %~1 GTR 80 goto :alarm, set 80 to be whatever threshold you want to alert. The other line we can modify has the other 2 variables you might want to change. if %count% gtr 5 call c:CPUalert.bat You can change the 5 to however many time the threshold must be broken in a row for you to be alerted. The count is reset every time the measured value is below the threshold. Finally, alert.bat is some alert script that will be triggered.
You might consider some command line utility email program like Blat - http://www.blat.net - which is free.
How does the thing work? The Alert Monitor alerts on every check since we set it to zero. On every alert, we see if the measured value is above our threshold. If it is above, we append a 1 to a text file (output.txt). We keep appending a 1 on every check over the threshold. We then count to see how many lines have a 1 in them and if more than 5 do, we trigger the alert. (This is how we only get alerted when the value is more than 1 check.)
Anytime the measured value is below the threshold, it writes a 0 to the text file which erases any previous 1’s or 0’s.
As you can see, this is a basic batch script. You could modify this for memory, mail queue or other alerts too.