I have a Windows 2003 Server and i need to code a service which would email me when the cpu usage stays over 90% for more than 5 minutes. How could i do that?
3 Answers
First you would have the read the processor load like:
How to get the CPU Usage in C#?
Second, you would have to use a timer which checks for processor time in some interval. The standard Timer from .Net is properly precise enough when we talk 5 min. The interval could be something like a few seconds. On Tick, you measure the CPU and if it is LOWER than 90% then reset some start-DateTime and if it is OVER 90% then check if the start-DateTime is over 5 min old.
And last you would need to send a mail like this:
This way uses a SMTP server which you can install local or otherwise you properly have a SMTP for one of your e-mail etc. You can also send a mail without with more overhead. Search Stackoverflow for that :)

- 1
- 1

- 17,622
- 5
- 63
- 99
Your windows service would need to inoke WMI in a manner similar to this periodically and determine whether to notify you.

- 133,658
- 13
- 134
- 193
Read the appropriate performance counter at a suitable interval. If the collected data meets your criterion then perform the action you want.
Many things like this can already been done with tools like performance monitor's alerts (including launching an application).

- 106,783
- 21
- 203
- 265