Click here to Skip to main content
15,746,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My application is hosted on 5-6 servers, I need to develop a window service which will run on my machine and will give me a alert if CPU utilization gets more than some set limit for more than 30 min.

I got a sample code through which I can get the result but for this I need to host this service on each machine which I dont want.

C#
public int getCPUCounter()
   {

       PerformanceCounter cpuCounter = new PerformanceCounter();
       cpuCounter.CategoryName = "Processor";
       cpuCounter.CounterName = "% Processor Time";
       cpuCounter.InstanceName = "_Total";

       // will always start at 0
       dynamic firstValue = cpuCounter.NextValue();
       System.Threading.Thread.Sleep(1000);
       // now matches task manager reading
       dynamic secondValue = cpuCounter.NextValue();

       return secondValue;

   }


Thanks in advance
Posted
Updated 17-Feb-15 22:12pm
v2
Comments
StM0n 18-Feb-15 4:48am    
Mhm... have you tried WMI, like http://www.codeproject.com/Articles/18122/Howto-Almost-Everything-in-WMI-via-C-Part-Regist
suhel_khan 19-Feb-15 1:12am    
I tried this but no luck

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900