1
votes

I'm trying to read the Performance Counters in the category "HTTP Service Request Queues" in my Azure worker role application (C#).

By default the application can not get any counter from that category, i.e.

  string performanceCategoryName = "HTTP Service Request Queues";
  var httpQueueCategory = PerformanceCounterCategory.GetCategories().FirstOrDefault(category => category.CategoryName == performanceCategoryName);

gives null.

However, if I remote desktop in to the instance and start perfmon, I can see the category there. And if I view it from perfmon and then restart the application, then the application can also read the counters. As if perfmon create the counter and it isn't there by default.

Does anybody know of a work around for this?

1

1 Answers

0
votes

I solved this by starting a cmd-process and calling "typeperf -q "from within my application after the owin listener has been started.

This had the same effect as opening perfmon, i.e. the categories that weren't there by default now become available to my application. Make sure you wait for the typeperf listing to finish before trying to access the counter category (this takes ~20 sec on a small azure worker role instance).

This is what worked for me:

        var startInfo = new ProcessStartInfo()
        {
            WindowStyle = ProcessWindowStyle.Hidden,
            FileName = "cmd.exe",
            Arguments = "/C typeperf.exe -q",
        };
        Process p = new Process() { StartInfo = startInfo };
        p.Start();
        p.WaitForExit(2*60*1000);

       string performanceCategoryName = "HTTP Service Request Queues";

       var httpQueueCategory = PerformanceCounterCategory.GetCategories().FirstOrDefault(category => category.CategoryName == performanceCategoryName);

Notice that it's important to do the listing after you register your applications http listener. Otherwise your instance won't be available. I noticed this because I tried to run the cmd as a startup task before the worker role started, but this didn't work.