Archive
Performance Counter InstanceName issue
I was creating a performance counter collection to register the processing time for ASP.NET requests, and I decided the best way to name instances was to use Request.Url.Authority + Request.Url.PathAndQuery. This counters would allow me to check average response time, total requests and requests per second, for each Request.Url.Authority + Request.Url.PathAndQuery.
I built the counters and I decided to create a _total instance too, to sum up all the requests being made to the server.
Rarely, the _total instance worked like a charm when looking at it in PerfMon, but the other instances (for example, localhost/Test.aspx?query=x) didn’t show a value, they all showed “—” in the report view of PerfMon. I had no idea what the problem was, but I saw that the failing counters showed up in the counters list with localhost in the Parent column and Test.aspx?query=x in the Instance column.
After some research I found something in this link (http://msdn2.microsoft.com/EN-US/library/aa373193.aspx):
PDH uses the following special characters in a counter path. Providers should not use these characters in their names. If a provider uses these special characters, PDH cannot parse the full counter path to obtain the counter and instances names.
Character Description Generic separator for computer, object, and counter. ( Beginning of instance name. ) Ending of instance name. / Separates instance and parent instance. #n Identifies a specific occurrence of a same-named instance. * Wildcard character.
So I decided to replace the mentioned characters which could definetively appear in the InstanceName I was creating with ‘_’ character, and it fixed the problem right away.