Monitor application via Application Insights and send alert: Part 2 Understand Telemetry Types and use advanced monitoring
Tags: applicationinsights, monitor, operation
Published: 2020-02-27 14:05:48

---
title: Monitor application via Application Insights and send alert: Part 2 Understand Telemetry Types and use advanced monitoring
published: true
description: Monitor application via Application Insights
tags: ApplicationInsights,Monitor,Operation
---

In the [previous post](https://dev.to/kenakamu/monitor-application-via-application-insights-part-1-set-rule-and-action-45k4), I setup very basic alert by using Application Insights and Azure Monitor Alert. In this article, I take a look into advanced scenario.

# Metrics and Logs

When I query the Application Insights, I obviously see the "log" type of data.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/i8pajp4nn1ybtkezkj4i.jpg)

However, when it looks like "metric" in the dashboard or in the alert settings. [Log-based and pre-aggregated metrics in Application Insights](https://docs.microsoft.com/en-us/azure/azure-monitor/app/pre-aggregated-metrics-log-metrics) explain the different between **log** and **metric**.

According to the article, there are two types of metrics exists.

**[Log-based Metrics](https://docs.microsoft.com/en-us/azure/azure-monitor/app/pre-aggregated-metrics-log-metrics#log-based-metrics)**

This is the traditional (or current in my environment) metric. As name infers, metric is created based on the log file. The article says:
> Using logs to retain a complete set of events can bring great analytical and diagnostic value.

But at the same time, it also says:

>At the same time, collecting a complete set of events may be impractical (or even impossible) for applications that generate a lot of telemetry

**[Pre-aggregated Metrics](https://docs.microsoft.com/en-us/azure/azure-monitor/app/pre-aggregated-metrics-log-metrics#pre-aggregated-metrics)**

This is metrics I expected, and I realize the fact that it's pre-aggregated. Yes of course, otherwise it sends too much data, and that's why it has max, min, average values. The article explains:

>they are stored as pre-aggregated time series, and only with key dimensions. This makes the new metrics superior at query time.

There is one interesting **important** note in the article.

> **Important**

>Both, log-based and pre-aggregated metrics coexist in Application Insights. To differentiate the two, in the Application Insights UX the pre-aggregated metrics are now called "Standard metrics (preview)", while the traditional metrics from the events were renamed to "Log-based metrics".

It maybe a bit confusing to see the standard one is in preview, but at the moment, it seems "preview" is gone already.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qnoipvpldlmx7bwncn58.jpg)

In any case, if I understand the concept, I won't be confused.

### SDK support

The article mentioned that only .NET SDK support pre-aggregated metrics so far. However I still can take advantages of the new feature as it clearly says:

> while you don't benefit from the reduced volume of data transmitted over the wire, you can still use the pre-aggregated metrics and experience better performance and support of the near real-time dimensional alerting with SDKs that don't pre-aggregate metrics during collection.

This is very important as I need to get urgent alert as real-time as possible.

# Create Metrics Chart and Alert

To create metric base chart, I can use [Azure Monitor Metrics Explorer](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-getting-started).

1\. Go to Application Insights resource and select "Metrics".

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/w55hvjg5bsvegey5wba5.jpg)

2\. I selected "standard metric" and "HTTP request execution time". Select whatever you want.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y65v1e27ys9zxu3tf4xb.jpg)

3\. I can further customize the chart by splitting, applying additional filter which I can see all the detail at [Advanced features of Azure Metrics Explorer](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-charts). But the main purpose in this article is to create alert, I click "New alert rule" which navigated me to the "Create rule" page. I can see both RESOURCE and CONDITION are pre-filled. There is an error in condition, as I need to set threshold. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9vy3lpxv7rzzkgt16z8g.jpg)

4\. Click the condition to open it, and set the threshold.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/womu4m93axmwk359h3s8.jpg)

The rest is same. Only difference is where I start adding the alert but it's super useful to create alert by looking into actual data.

# Smart Detection

I keep explaining about how Application Insights uses Azure Monitor to send alert. But it also provides excellent out-of-box service which you cannot get without Application Insights. One of such features is [Smart Detection](https://docs.microsoft.com/en-us/azure/azure-monitor/app/proactive-diagnostics)

First thing first. How to configure it? The answer is, nothing. It's on by default and send me alert(s) by using Machine Learning, so I just need to know what kind of information I will get, and how to look into logs.

### What problems are detected?

According to the article, Smart Detection detects and notifies about a variety of issues, such as:

- **[Smart detection - Failure Anomalies](https://docs.microsoft.com/en-us/azure/azure-monitor/app/proactive-failure-diagnostics)**: We use machine learning to set the expected rate of failed requests for your app, correlating with load and other factors. If the failure rate goes outside the expected envelope, we send an alert.
- **[Smart detection - Performance Anomalies](https://docs.microsoft.com/en-us/azure/azure-monitor/app/proactive-performance-diagnostics)**: You get notifications if response time of an operation or dependency duration is slowing down compared to historical baseline or if we identify an anomalous pattern in response time or page load time.
- General degradations and issues, like [Trace degredation](https://docs.microsoft.com/azure/azure-monitor/app/proactive-trace-severity), [Memory leak](https://docs.microsoft.com/azure/azure-monitor/app/proactive-potential-memory-leak), [Abnormal rise in Exception volume](https://docs.microsoft.com/azure/azure-monitor/app/proactive-exception-volume) and [Security anti-patterns](https://docs.microsoft.com/azure/azure-monitor/app/proactive-application-security-detection-pack).

I can see the settings from "Smart Detection" area by click "Settings".

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6lllhv46ekvtj5tuuwcj.jpg)

# Dynamic Threshold

Azure Monitor actually has similar capability, which is called "dynamic threshold" which I see the option several times when I create alert.

[Metric Alerts with Dynamic Thresholds in Azure Monitor](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-dynamic-thresholds) explains the detail.

The image below illustrate the concept very well.

![](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/media/alerts-dynamic-thresholds/threshold-picture-8bit.png)

Use the following information to interpret the previous chart.

**Blue line** - The actual measured metric over time.
**Blue shaded area** - Shows the allowed range for the metric. As long as the metric values stay within this range, no alert will occur.
**Blue dots** - If you left click on part of the chart and then hover over the blue line, you see a blue dot appear under your cursor showing an individual aggregated metric value.
**Pop-up with blue dot** - Shows the measured metric value (the blue dot) and the upper and lower values of allowed range.
**Red dot with a black circle** - Shows the first metric value out of the allowed range. This is the value that fires a metric alert and puts it in an active state.
**Red dots**- Indicate additional measured values outside of the allowed range. They will not fire additional metric alerts, but the alert stays in the active.
**Red area** - Shows the time when the metric value was outside of the allowed range. The alert remains in the active state as long as subsequent measured values are out of the allowed range, but no new alerts are fired.
**End of red area** - When the blue line is back inside the allowed values, the red area stops and the measured value line turns blue. The status of the metric alert fired at the time of the red dot with black outline is set to resolved.

As you can see, this types of metrics behavior is very hard to set "static alert". It may require many data to start working more precisely, but it worse trying.

# Summary

In this article, I explain advanced features of Application Insights and Azure Monitor Alert. I love smart detection and dynamic alert as it's so easy to set, but I need to understand what kind of alert I can get.

In the next article, I will explain how to "optimize" alerts.

[Go to next article](https://dev.to/kenakamu/monitor-application-via-application-insights-and-send-alert-part-3-optimize-telemetry-and-alerts-17a9)