Are CounterSample
instances returned from PerformanceCounter.NextSample()
configurable? Can I configure the counter and sampling e.g. to query instant values 5 times a minute and give me an average for 5 minutes? How is the sampling determined?
Here is an example of the Processor/% Processor Time for _Total
var procProcTime = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
var sample = procProcTime.NextSample();
do
{
await Task.Delay(_delay5Minutes);
var newSample = procProcTime.NextSample();
var avg5Minutes = CounterSample.Calculate(sample, newSample);
}
while (!token.IsCancellationRequested);
Trying to reverse engineer the docs is painful. Since the CounterSample
has readonly properties, it looks like the counter provider (in this example, Processor/% Processor Time) predetermines the sampling?
These docs are amazingly full but amazingly difficult to understand.