Monitoring Custom Performance Counters in Application Insights

Monitoring Custom Performance Counters in Application Insights

Rate This
  • Comments 1

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”

image

 

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
PerformanceCounter2.Increment()

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

image

 

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 “categoryname\countername”.

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="\chass\ChassCounterName"/>
  </PerformanceCounters>

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

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).

image

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

image

Leave a Comment
  • Please add 2 and 1 and type the answer here:
  • Post
  • Great, thanks for sharing.

Page 1 of 1 (1 items)