How to work with Performance counters and WCF service in IIS?

无人久伴 提交于 2019-11-30 20:15:36

WCF services includes performance counters that you can track with the Windows Performance Monitor (Perfmon.exe). You can launch this from the Administrative Tools in Windows Server 2003.

Performance counters can be enabled from the diagnostics section of the .config file for the service, as shown in the following sample configuration:

<configuration>
  <system.serviceModel>
    <diagnostics performanceCounters="All" /> 
  </system.serviceModel>
</configuration>

You may want to check out these articles which can guide you on how to use the performance counters for WCF services:

It looks like this might be a bug (or a design-feature) with how performance counters work. After some poking, I've found this on the MSDN forums:

I have the same problem. It appears that Microsoft truncates the tail end of the operation name when naming the counter instance. They replace the truncated part with some sort of 2-digit base-10 magic number. I'm guessing it's a hash, but who knows how it's actually generated. The rub is that this number is not guaranteed unique and can cause collisions in counter names. If such a collision happens, it seems to cause all Endpoint and Operation counters to vanish (at least for me).

I have two methods named UpdateMarkupChunk and UpdateMarkupCancel. If I comment out one or the other so that the other doesn't exist, they both resolve to UpdateMarkupC53 in the counter instance name. When I comment them both in, none of the counter instances appear for ServiceModelEndpoint or ServiceModelOperation.

Can you suggest a workaround for this, Microsoft? I have a production service already in place that I would like to monitor, and changing the operation names is not an option.

And Microsoft responded with:

You are correct. And this behaviour is by design. There is a limit on the length of a performance counter instance's name.

Operation performance counters are found under the ServiceModelOperation 4.0.0.0 performance object when viewing with the Performance Monitor (Perfmon.exe). Each operation has an individual instance. That is, if a given contract has 10 operations, 10 operation counter instances are associated with that contract. The object instances are named using the following pattern:

(ServiceName).(ContractName).(OperationName)@(first endpoint listener address)

When a Windows Communication Foundation (WCF) counter instance name exceeds the maximum length, WCF replaces a portion of the instance name with a hash value.

So it seems because of this maximum name limitation, the large chances of a hash collision when there's only a two-digit hash suffix, and that when two instances of a counter have the same name, it wipes out the entire counter that it's not actually possible.

Which is more than a little frustrating. So unless Microsoft fixes this problem (either long hash values, or better collision handling by perf counters), or provides a suitable workaround we are working blind.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!