We have a Windows 2003 server where 3 services are running constantly. Sometimes these services consume over 90% CPU. Restarting these services returns normalcy. I need a script/program that will constantly monitor CPU usage and if usage is high then restart those services.
After a bit of research I found this script to monitor CPU usage from Technet.
Script to monitor CPU usage:
(get-counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 10 | select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average
This monitors the CPU usage for 10 seconds and then displays the averaged output.
Now all I need is for the CPU usage script to call the service restart scripts when the condition that usage is >90% is met. Any help would be appreciated.