Monitoring Custom Performance Counters in Application Insights

I have had several folks ask me how to monitor custom performance counters in Application Insights.

Since I hadn’t played with performance counters in a while I thought I would go through the MSDN documentation on this topic from end to end.

Step 1.  Create the performance Counter

In Visual Studio open Server Explorer, expand the Performance Counters node and right click “Create New Performance Category”



Step 2.  Create an Application that increments the counter

In Windows Forms you can just drag the performance counter to the design surface but it is not much harder in a Web Application.

Here is the code for Visual Basic:

Dim PerformanceCounter2 As System.Diagnostics.PerformanceCounter = New System.Diagnostics.PerformanceCounter()
PerformanceCounter2.CategoryName = "chass"
PerformanceCounter2.CounterName = "ChassCounterName"
PerformanceCounter2.MachineName = "aidemo008"
PerformanceCounter2.ReadOnly = False

At this point you should be able to see your application increment the counter in Perfmon.



Step 3.  Add the performance counter to your Application Insights Configuration File. 
To add these entries open your Applicationinsights config file in your solution. This assumes you are using the Application Insights Tools for Visual Studio; these entries have the format “categorynamecountername”.

More information can be found in MSDN documentation on this topic

<!– Controlling which performance counters are collected by Microsoft Monitoring Agent. –>
  <PerformanceCounters enabled="true">
      <PerformanceCounterConfiguration counterSpecifier="chassChassCounterName"/>

    <!– Microsoft Monitoring Agent always collects a predefined set of performance counters (such as 

Step 4. View the Custom Performance Counter in Application Insights

You can view the custom metric two places in Application Insights.  Under Diagnostics go to Metrics >Edit Metrics and select your custom metric(s).


Or as a new tile in a dashboard –this can either be single-metric or multi-metric tile.

      <p><a href=""><img title="image" style="border-top: 0px;border-right: 0px;border-bottom: 0px;padding-top: 0px;padding-left: 0px;border-left: 0px;padding-right: 0px" border="0" alt="image" src="" width="852" height="611" /></a></p>


Comments are closed. Login to edit/delete your existing comments