0
votes

I read about the difference between log-based and pre-aggregated metrics here: https://docs.microsoft.com/en-us/azure/azure-monitor/app/pre-aggregated-metrics-log-metrics

Later on I came across event counters: https://docs.microsoft.com/en-us/azure/azure-monitor/app/eventcounters

They both seem to be used to track metrics of some kind. I see the EventCounters documentation doesn't mention any (pre-)aggregation, but besides that, what is the difference between both and when do I use an EventCounter rather than making a call to TelemetryClient.TrackMetric()?

1

1 Answers

4
votes

TelemetryClient.TrackMetric() is specific to application insights, EventCounter is not.

EventCounter is a mechanism in .Net to define custom metrics inside an application/library. You have to create a listener for them to read out the values and possible send those values somewhere. This could be a simple console output, a logging framework or something else like Application Insights. It decouples the generation of metric from the consumption of those metrics.

If an application or library you are using already defines metrics using EventCounters you can publish them as metrics in Application Insights. The referenced documentation tells you how to do that.

If you write your own code and what to track custom metrics in Application Insights you can decide yourself. Using TrackMetric is the fastest and easiest option but you might loose some flexibility when you want to publish the metrics somewhere else.

I wrote a blogpost about EventCounters a while ago, if you're interested in the why and the how.