Skip to main content

Using Event Counters with Application Insights

When adding the Application Insights SDK to your application, a set of Performance Counters is tracked by default.

This is the list of default counters for ASP.NET web applications:

  • % Process\Processor Time
  • % Process\Processor Time Normalized
  • Memory\Available Bytes
  • ASP.NET Requests/Sec
  • .NET CLR Exceptions Thrown / sec
  • ASP.NET ApplicationsRequest Execution Time
  • Process\Private Bytes
  • Process\IO Data Bytes/sec
  • ASP.NET Applications\Requests In Application Queue
  • Processor(_Total)\% Processor Time

However Performance Counters are a windows only feature. With .NET being cross-platform, is there a solution that works on both Windows and Linux?

Of course there is! (Otherwise I wouldn’t be writing this blog post).

Collecting EventCounters with Application Insights

The documentation has the following to say about EventCounters:

EventCounter is .NET/.NET Core mechanism to publish and consume counters or statistics. EventCounters are supported in all OS platforms - Windows, Linux, and macOS. It can be thought of as a cross-platform equivalent for the PerformanceCounters that is only supported in Windows systems.

By default no EventCounters are collected, but they are easy to add by configuring the EventCounterCollectionModule:

Probably the hardest thing when implementing EventCounters is finding the list of built-in counters.

Here is an example where I added some extra EventCounters from ASP.NET Core:

Viewing EventCounters data in Application Insights

To view the tracked EventCounters, you need to look at the ‘Custom’ category inside the Log-based metrics namespace:

 

Popular posts from this blog

XUnit - Assert.Collection

A colleague asked me to take a look at the following code inside a test project: My first guess would be that this code checks that the specified condition(the contains) is true for every element in the list.  This turns out not to be the case. The Assert.Collection expects a list of element inspectors, one for every item in the list. The first inspector is used to check the first item, the second inspector the second item and so on. The number of inspectors should match the number of elements in the list. An example: The behavior I expected could be achieved using the Assert.All method:

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

Angular --deploy-url and --base-href

As long you are running your Angular application at a root URL (e.g. www.myangularapp.com ) you don’t need to worry that much about either the ‘--deploy-url’ and ‘--base-href’ parameters. But once you want to serve your Angular application from a server sub folder(e.g. www.mywebsite.com/angularapp ) these parameters become important. --base-href If you deploy your Angular app to a subfolder, the ‘--base-href’ is important to generate the correct routes. This parameter will update the <base href> tag inside the index.html. For example, if the index.html is on the server at /angularapp/index.html , the base href should be set to <base href="/angularapp/"> . More information: https://angular.io/guide/deployment --deploy-url A second parameter that is important is ‘--deploy-url’. This parameter will update the generated url’s for our assets(scripts, css) inside the index.html. To make your assets available at /angularapp/, the deploy url should