I want to use the built in performance counter MaxQueueItemAge from the “HTTP Service Request Queues” to measure how long the latest request to my application waited in the IIS queue.
This is how I initialize it:
var maxQueueAgeCounter = new PerformanceCounter(@"HTTP Service Request Queues", "MaxQueueItemAge", "<my app pool name>", true);
And I retrieve the measure like this:
var value = maxQueueAgeCounter.NextValue();
But this always returns 0.
I also tried getting the RawValue:
var raw = maxQueueAgeCounter.NextSample().RawValue;
but that returns some number that seems arbitrary, and remains fixed in every sample (even when requests flow in and out of the queue).
I know this metric works because when I use windows’ perfmon tool the counter shows the actual values:
I tested other counters from my code and they work well, for instance this returns the correct number of requests in the queue:
var queueSizeCounter = new PerformanceCounter(@"HTTP Service Request Queues", "CurrentQueueSize", "<my app pool name>", true);
var value = queueSizeCounter .NextValue();
1