Basic C# Apm Application Error: {SystemTotalCpuProvider} Failed instantiating PerformanceCounter

Kibana version: 7.3

Elasticsearch version: 7.3

APM Server version: 7.3

Hello all,

I am trying to implement a very basic C# apm application.

This is the code in my main:

When the line executes that tries to start a transaction I get this error:

[2019-09-20 05:02:42][Error] - {SystemTotalCpuProvider} Failed instantiating PerformanceCounter - please make sure the current user has permissions to read performance counters. E.g. make sure the current user is member of the 'Performance Monitor Users' group
Exception: System.InvalidOperationException, Message: Category does not exist.

Which is clearly a reference to the CPU usage metric gathering. I read online that this is a issue with administrative privileges, however when I run VS in admin mode, I still get this error.

Can anyone help?

Hi @LordMathis,

It seems we have a bug in .NET Agent and I opened an issue to investigate - Unfortunately it's quite possible that the log message is misleading and mistakenly assumes that the root cause is missing permissions. So far we saw that in the case where root cause was a permission problem the exception was UnauthorizedAccessException and not InvalidOperationException but we cannot rule out a permissions problem for sure until we find the root case.
Which bring me to the main problem - PerformanceCounter failure. We would like to reproduce it in our environment in order to investigate. Could you please provide more details about your environment:

  1. What is the OS (desktop/server Windows) and its version?
  2. What is the .NET runtime (.NET Framework or .NET Core) and its version?

1.) My OS is windows 10, Version 10.0.14393
2.) Then I'm using Microsoft.NetCore.App Version 2.1.0

Thank you @LordMathis
The issue is still not reproducible in our environment. Could you please run the following commands (from the command line with admin permissions) and post the results:

TypePerf "\Processor(_Total)\% Processor Time"


TypePerf "\Processor Information(_Total)\% Processor Time"

Note that each of these command runs until stopped with Control-C - a couple lines of output will be enough. Thank you in advance.

@LordMathis Another question - does your OS have non-English default locale? It seems that Performance Counters names dependent on OS locale.

When I run the top command I get "No valid counters."

When I run the second command I get a list. Here are a few:

"09/23/2019 09:59:39.952","17.091082"
"09/23/2019 09:59:40.954","17.269345"
"09/23/2019 09:59:41.955","23.498969"
"09/23/2019 09:59:42.957","32.148931"
"09/23/2019 09:59:43.957","28.722477"
"09/23/2019 09:59:44.958","21.555412"
"09/23/2019 09:59:45.959","21.424650"
"09/23/2019 09:59:46.960","19.195319"

My OS should be in english.

I looked up this no valid counters error and found someone online suggesting that I run perfmon on windows. When I did I get the following:
So it would appear there is a issue with my performance counter list.

I resolved this be recreating my performance counters. To do this, open command prompt in admin mode, then run the command "lodctr /r":

This also fixed the issue within the actual agent and now the agent is running as expected. Thank you for the help @Sergey_Kleyman.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.