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

**URL:** <https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [September 20, 2019, 5:17pm UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467 "2019-09-20T17:17:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![LordMathis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lordmathis/32/55044_2.png) [@LordMathis](https://discuss.elastic.co/u/LordMathis)\
**Post date:** [September 20, 2019, 5:17pm UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/1 "2019-09-20T17:17:03Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/6/76006d587c380174c5c4bda8324c9a072b6c1e6e.png)

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?

---

<div class="post-metadata">

**Author:** ![Sergey\_Kleyman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergey_kleyman/32/39333_2.png) [@Sergey\_Kleyman](https://discuss.elastic.co/u/Sergey_Kleyman)\
**Post date:** [September 20, 2019, 6:43pm UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/2 "2019-09-20T18:43:26Z")

</div>

Hi @LordMathis,

It seems we have a bug in .NET Agent and I opened an issue to investigate - [https://github.com/elastic/apm-agent-dotnet/issues/501](https://github.com/elastic/apm-agent-dotnet/issues/501). 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?

---

<div class="post-metadata">

**Author:** ![LordMathis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lordmathis/32/55044_2.png) [@LordMathis](https://discuss.elastic.co/u/LordMathis)\
**Post date:** [September 20, 2019, 7:09pm UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/3 "2019-09-20T19:09:13Z")

</div>

> [@LordMathis](#):
>
> Failed instantiating PerformanceCounter

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

---

<div class="post-metadata">

**Author:** ![Sergey\_Kleyman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergey_kleyman/32/39333_2.png) [@Sergey\_Kleyman](https://discuss.elastic.co/u/Sergey_Kleyman)\
**Post date:** [September 21, 2019, 7:21am UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/4 "2019-09-21T07:21:50Z")

</div>

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:

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

```

and

```auto
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.

---

<div class="post-metadata">

**Author:** ![Sergey\_Kleyman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergey_kleyman/32/39333_2.png) [@Sergey\_Kleyman](https://discuss.elastic.co/u/Sergey_Kleyman)\
**Post date:** [September 21, 2019, 7:35am UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/5 "2019-09-21T07:35:54Z")

</div>

@LordMathis Another question - does your OS have non-English default locale? [It seems that Performance Counters names dependent on OS locale](https://stackoverflow.com/questions/39347779/category-does-not-exist-while-creating-performance-counter-for-ram-usage).

---

<div class="post-metadata">

**Author:** ![LordMathis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lordmathis/32/55044_2.png) [@LordMathis](https://discuss.elastic.co/u/LordMathis)\
**Post date:** [September 23, 2019, 2:00pm UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/6 "2019-09-23T14:00:55Z")

</div>

> [@Sergey\_Kleyman](#):
>
> TypePerf "\Processor Information(\_Total)% Processor Time"

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"

---

<div class="post-metadata">

**Author:** ![LordMathis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lordmathis/32/55044_2.png) [@LordMathis](https://discuss.elastic.co/u/LordMathis)\
**Post date:** [September 23, 2019, 2:01pm UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/7 "2019-09-23T14:01:29Z")

</div>

My OS should be in english.

---

<div class="post-metadata">

**Author:** ![LordMathis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lordmathis/32/55044_2.png) [@LordMathis](https://discuss.elastic.co/u/LordMathis)\
**Post date:** [September 23, 2019, 3:04pm UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/8 "2019-09-23T15:04:29Z")

</div>

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:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/2/324dbafec5641705de523222115de06673943443.png)  
So it would appear there is a issue with my performance counter list.

---

<div class="post-metadata">

**Author:** ![LordMathis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lordmathis/32/55044_2.png) [@LordMathis](https://discuss.elastic.co/u/LordMathis)\
**Post date:** [September 23, 2019, 3:19pm UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/9 "2019-09-23T15:19:58Z")

</div>

> [@Sergey\_Kleyman](#):
>
> TypePerf "\Processor(\_Total)% Processor Time"

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

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/f/cf762213a8a069290bcde4b35b4d9ad53097cf96.png)

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 14, 2019, 11:20am UTC](https://discuss.elastic.co/t/basic-c-apm-application-error-systemtotalcpuprovider-failed-instantiating-performancecounter/200467/10 "2019-10-14T11:20:04Z")

</div>

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