You must Sign In to post a response.
  • Category: .NET

    Query to fetch PC utilization

    Trying to integrate .net application with SCOM . Need queries through which I can display information like CPU Utilization , Memory Usage , Number of Processes running on the client machine . SCOM has its own database but unable to create a query that can fetch the said information.
  • #765073
    PerformanceCounter class will help you to get CPU utilization, you might check below snippet
    private static void RunTest(string appName)
    {
    bool done = false;
    PerformanceCounter total_cpu = new PerformanceCounter("Process", "% Processor Time", "_Total");
    PerformanceCounter process_cpu = new PerformanceCounter("Process", "% Processor Time", appName);
    while (!done)
    {
    float t = total_cpu.NextValue();
    float p = process_cpu.NextValue();
    Console.WriteLine(String.Format("_Total = {0} App = {1} {2}%\n", t, p, p / t * 100));
    System.Threading.Thread.Sleep(1000);
    }
    }
    you need to pass program name to get its CPU utilization

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765111
    Hi,
    For CPU usage information, you can use System.Diagnostics.PerformanceCounter namespace.
    Please go through this URL:
    http://stackoverflow.com/questions/4679962/what-is-the-correct-performance-counter-to-get-cpu-and-memory-usage-of-a-process?lq=1
    Whole project:
    http://www.codeproject.com/Articles/10258/How-to-get-CPU-usage-of-processes-and-threads
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com


Sign In to post your comments