Get a Performance Counter using English name

Posted on Posted in C#

Get a single-instance PerformanceCounter

Each counter has its own category and name (sometimes also an instance name). To read performance data, we can create an instance like this:

var counter = new PerformanceCounter("IPv4", "Datagrams/sec");

Unfortunately those names in parameters depend on system language. However, there is a way to get the PerformanceCounter knowing only the English name.

Get localized names

WinAPI function PdhLookupPerfNameByIndex gets a localized name, although we need to know first what’s the PerformanceCounter’s ID (which can be different on each computer).

Fortunately the list with English names and IDs is stored in registry value:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009\Counter

It looks like this:


One more issue

While listing counters names I noticed, that for some categories they are localized and for some they are in English. This means we can’t rely on localized names – just in case we have to check all possible combinations of localized and non-localized names.

Source code

More information: MSDN – Using PDH APIs correctly in a localized language