Search code examples
asp.nethttpmoduleperformancecounter

PerformanceCounters updated in HttpModule are not updating in PerfMon


I am trying to add PerformanceCounter logging as part of our WebForms application. I am attempting to port an MVC implementation that uses ActionFilters to write request durations per controller action to custom performance counter instances here.

My implementation is to write an HttpModule that logs the OnBeginRequest and OnEndRequest to write to these custom performance counters. However, when I view in PerfMon, I can see the instances of my counters show up in PerfMon, but the values are all empty ("------").

I am initializing the performance counter using the following code:

var counter = new PerformanceCounter {
    CategoryName = categoryName,
    CounterName = counterName,
    InstanceName = instanceName,
    ReadOnly = false,
    InstanceLifetime = PerformanceCounterInstanceLifetime.Process,
    RawValue = 0,
};

Even if I didn't update the value, I would assume that the Last value would be 0, but instead it is '-------'.

The code in the sample associated with the article does work and uses the same syntax. I did notice that the counters written by the MVC attribute have no 'Parent' but the ones created by the WebForms module have a parent specified. I don't know if this has anything to do with it.

I have checked to ensure that no errors are being recorded in the Event log. I would appreciate guidance on why my performance counters are not updating.

Thanks

UPDATE 6/5/2014 I discovered that the issue was a '/' in the instance name, which gets turned into parent/instance which cannot be found once created. Make sure that you clean up your instance name to ensure that no forward slashes exist, or you won't be able to update the values.


Solution

  • I discovered that the issue was a forward slash ('/') in the instance name I was assigning, which gets split into parent/instance which cannot be found once created. Make sure that you clean up your instance name to ensure that no forward slashes exist, or you won't be able to update the performance counter's values.