Bug 1772 - Mono performance counters all return 0
Summary: Mono performance counters all return 0
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2011-10-28 15:12 UTC by Jai
Modified: 2017-07-11 21:17 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jai 2011-10-28 15:12:22 UTC
I installed mono 2.10.6 and followed instructions on


and used the following counters as suggested 

% User Time under Processor
Requests/Sec under ASP.NET
Thread Count under Process

All come out as zero when run using mono runtime.

Code snippet:

I run the following in a loop:

 if (!PlatformID.Win32NT.Equals(Environment.OSVersion.Platform))
                processor = new PerformanceCounter("Process", "% Processor Time");
                requests = new PerformanceCounter("ASP.NET", "Requests Total");
                obj= new PerformanceCounter("Mono Memory ", "Allocated Objects");
                threads = new PerformanceCounter("Process", "Thread Count");
                availBytes = new PerformanceCounter("Mono Memory", "Total Physical Memory");
                bytes = new PerformanceCounter("Network Interface", "Bytes Total/sec");
                threadpool = new PerformanceCounter("Mono Threadpool", "# of IO Threads");
Comment 1 Paolo Molaro 2011-11-02 10:11:38 UTC
You need to specify the instance name of the performance counter.
For process-based counters this is the pid of the process:
  counter.InstanceName = Process.GetCurrentProcess().Id.ToString();

For other counters you can query the performance category for the instance names available
Comment 2 Jai 2011-11-02 12:27:36 UTC
OK that helped - adding instance to Process as Process.GetCurrentProcess().Id.ToString() gave me results.

For the other counters, I used the instance name to be "_Total" as this was one of the instance names printed with GetInstanceNames(). But those were all still 0. Tried instead with "mono" but still 0.

            string instanceName = "_Total";          
            if (!PlatformID.Win32NT.Equals(Environment.OSVersion.Platform))
                processor = new PerformanceCounter
                                    CategoryName = "Process",
                                    InstanceName = Process.GetCurrentProcess().Id.ToString(),
                                    CounterName = "% Processor Time"
                threads = new PerformanceCounter
                    CategoryName = "Process",
                    InstanceName = Process.GetCurrentProcess().Id.ToString(),
                    CounterName = "Thread Count"

                PerformanceCounterCategory[] categories = PerformanceCounterCategory.GetCategories();
                foreach (PerformanceCounterCategory category in categories)
                    string[] instanceNames = category.GetInstanceNames();
                    foreach (string name in instanceNames)

                ioWrite = new PerformanceCounter("ASP.NET", "Requests Total", instanceName);
                ioRead = new PerformanceCounter("Mono Memory ", "Allocated Objects", instanceName);
                availBytes = new PerformanceCounter("Mono Memory", "Total Physical Memory", instanceName);
                diskRead = new PerformanceCounter("Network Interface", "Bytes Total/sec", instanceName);
                diskWrite = new PerformanceCounter("Mono Threadpool", "# of IO Threads", instanceName);
                Log("Win platform");