0

I am running a .net application in a windows docker container with Docker Desktop for Windows. When my app tries to create perf counters using this code:

_counter = new PerformanceCounter(categoryName, counterName, InstanceName, true);
//My categoryname  is Processor , CounterName is % Processor Time & instancename is _Total.

I am getting this exception:

Unhandled Exception: System.InvalidOperationException: Category does not exist. at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter) at System.Diagnostics.PerformanceCounter.InitializeImpl() at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)

This is the base image of my container: https://hub.docker.com/r/microsoft/dotnet-framework/

It has Windows Server core as part of it.

Appreciate any help in fixing this. I am not sure if this is just some windows setting I need to change here or is it because of the docker & windows or my code not able to access the categories of the perf counters.

It is working perfectly fine, when I run it in my local machine instead of a container.

Community
  • 1
  • 1
ashok
  • 95
  • 1
  • 7
  • I figured out few things : 1. It actually means that the category Processor is not present in my OS for some reason. When I tried to list all the performance categories by this code : PerformanceCounterCategory[] categories = PerformanceCounterCategory.GetCategories(); foreach (PerformanceCounterCategory category in categories) { Console.WriteLine("Category name: {0}", category.CategoryName); } There was not a category called Processor. Why is it missing in Windows Server 2016? – ashok Mar 13 '17 at 21:55

1 Answers1

0

As far as I know these should be working.

Can you try using TypePerf to query those counters? I see them on my system when I query them on the Windows Server core base image. Do they break in the container you built?

docker run microsoft/windowsservercore TypePerf "\Processor(*)\% Processor Time"

Does show CPU usage: "(PDH-CSV 4.0)","\\DF4E02B31BBD\Processor(0)\% Processor Time","\\DF4E02B31BBD\Processor(1)\% Processor Time","\\DF4E02B31BB D\Processor(_Total)\% Processor Time" "04/25/2017 09:52:34.412","50.536535","38.170669","44.353602" "04/25/2017 09:52:35.423","19.583557","2.572386","11.077971" "04/25/2017 09:52:36.425","39.207660","50.119106","44.663383" "04/25/2017 09:52:37.453","31.606146","43.765053","37.685600"