{"id":1413,"date":"2014-04-21T13:10:22","date_gmt":"2014-04-21T13:10:22","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2014\/04\/21\/monitoring-custom-performance-counters-in-application-insights\/"},"modified":"2022-07-17T23:48:48","modified_gmt":"2022-07-18T07:48:48","slug":"monitoring-custom-performance-counters-in-application-insights","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/monitoring-custom-performance-counters-in-application-insights\/","title":{"rendered":"Monitoring Custom Performance Counters in Application Insights"},"content":{"rendered":"<p>I have had several folks ask me how to monitor custom performance counters in Application Insights.<\/p>\n<p>Since I hadn\u2019t played with performance counters in a while I thought I would go through the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dn550723.aspx#custom\">MSDN documentation on this topic<\/a> from end to end.<\/p>\n<p><strong>Step 1.\u00a0 Create the performance Counter<\/strong><\/p>\n<p>In Visual Studio open Server Explorer, expand the Performance Counters node and right click \u201cCreate New Performance Category\u201d<\/p>\n<p><img decoding=\"async\" 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=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/04\/2605.image_thumb_0507C2ED.png\" width=\"465\" height=\"419\" \/><\/p>\n<p>\u00a0<\/p>\n<p><strong>Step 2.\u00a0 Create an Application that increments the counter<\/strong><\/p>\n<p>In Windows Forms you can just drag the performance counter to the design surface but it is not much harder in a Web Application.<\/p>\n<p>Here is the code for Visual Basic:<\/p>\n<blockquote>\n<p><font color=\"#9b00d3\"><strong>Dim PerformanceCounter2 As System.Diagnostics.PerformanceCounter = New System.Diagnostics.PerformanceCounter() <br \/>PerformanceCounter2.CategoryName = &#8220;chass&#8221; <br \/>PerformanceCounter2.CounterName = &#8220;ChassCounterName&#8221; <br \/>PerformanceCounter2.MachineName = &#8220;aidemo008&#8221; <br \/>PerformanceCounter2.ReadOnly = False <br \/>PerformanceCounter2.Increment()<\/strong><\/font><\/p>\n<\/blockquote>\n<p><font color=\"#000000\">At this point you should be able to see your application increment the counter in Perfmon. <\/font><\/p>\n<p><img decoding=\"async\" title=\"image\" style=\"border-top: 0px;border-right: 0px;border-bottom: 0px;padding-top: 0px;padding-left: 0px;margin: 0px;border-left: 0px;padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/04\/1638.image_thumb_5BFFB4A1.png\" width=\"484\" height=\"364\" \/><\/p>\n<p>\u00a0<\/p>\n<p><strong>Step 3.\u00a0 Add the performance counter to your Application Insights Configuration File.<\/strong>\u00a0<br \/>\nTo add these entries open your Applicationinsights config file in your solution. This assumes you are using the <a href=\"https:\/\/aka.ms\/aivsix\">Application Insights Tools for Visual Studio<\/a>; these entries have the format \u201ccategorynamecountername\u201d.<\/p>\n<p>More information can be found in <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dn550723.aspx#custom\">MSDN documentation on this topic<\/a><\/p>\n<blockquote>\n<p><font color=\"#9b00d3\"><strong><!-- Controlling which performance counters are collected by Microsoft Monitoring Agent. --> <br \/>\u00a0 <PerformanceCounters enabled=\"true\"> <br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 <PerformanceCounterConfiguration counterSpecifier=\"chassChassCounterName\"\/> <br \/>\u00a0 <\/PerformanceCounters><\/strong><\/font><\/p>\n<p><font color=\"#9b00d3\"><strong>\u00a0\u00a0\u00a0 <!-- Microsoft Monitoring Agent always collects a predefined set of performance counters (such as<\/strong><\/font>\u00a0<br \/>\n  \u00a0\u00a0<br \/>\n  <img decoding=\"async\" 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=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/04\/7411.image_thumb_6965C7A7.png\" width=\"711\" height=\"269\" \/><\/p>\n\n\n<\/blockquote>\n\n\n\n\n\n<p><strong>Step 4. View the Custom Performance Counter in Application Insights<\/strong><\/p>\n\n\n\n\n\n<p>You can view the custom metric two places in Application Insights.\u00a0 Under Diagnostics go to Metrics >Edit Metrics and select your custom metric(s).<\/p>\n\n\n\n\n\n<p><img decoding=\"async\" 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=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/04\/1172.image_thumb_48DE87F5.png\" width=\"858\" height=\"563\" \/><\/p>\n\n\n\n\n\n<p>Or as a new tile in a dashboard \u2013this can either be single-metric or multi-metric tile.<\/p>\n\n\n\n\n\n<pre><code>      &lt;p&gt;&lt;a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/04\/1581.image_thumb_06DAA965.png\"&gt;&lt;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=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/04\/1581.image_thumb_06DAA965.png\" width=\"852\" height=\"611\" \/&gt;&lt;\/a&gt;&lt;\/p&gt;\n<\/code><\/pre>\n\n\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have had several folks ask me how to monitor custom performance counters in Application Insights. Since I hadn\u2019t 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.\u00a0 Create the performance Counter In Visual Studio open Server Explorer, expand [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[224,1],"tags":[],"class_list":["post-1413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","category-devops"],"acf":[],"blog_post_summary":"<p>I have had several folks ask me how to monitor custom performance counters in Application Insights. Since I hadn\u2019t 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.\u00a0 Create the performance Counter In Visual Studio open Server Explorer, expand [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/1413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=1413"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/1413\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=1413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=1413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=1413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}