I been looking at PerformanceCounter Class for monitoring system performance. I have figured out how to call built in counters. What I'm struggling with is understanding the values that I get back and how compare those values to what I can see in Task Manager.
So far I have successfully been able to monitor available RAM in MB and it correctly corresponded to value in Task Manager.
first I created PerformanceCounter
myMemoryCounter = new PerformanceCounter("Memory", "Available MBytes", true);
Then I put the following line inside a loop.
Console.WriteLine("Value" + myMemoryCounter.NextSample().RawValue.ToString());
When looking at counters for processor, I'm not able to make connection to % CPU Utilization that can be observed in Task Manager.
Do I need to have multiple counters and compute the value or is there easier way?
Update:
Looking at question What is the correct Performance Counter to get CPU and Memory Usage of a Process? it just describes which counter to use but not how to convert results to percentage?
NextSample().RawValue
returns long data type and I need to know how to convert it to percentage.
Using the following code
var _myCPUCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
Console.WriteLine("CPU " + _myCPUCounter.NextSample().RawValue.ToString("0.000"));
I get this value 1794607539062
how do I convert that to percentage?