Monitoring .NET Core apps on Microsoft Azure: Introduction
By: Luis Felipe
Tags: Cloud Computing, Monitoring, Dotnet, Net Core, Azure

Before opening access to your app on a production environment, it is important to ensure that your app is consuming resources in an acceptable way. In order to check for any anomalous behavior that causes metrics such as CPU utilization to highly increase, monitoring comes to the rescue.

Microsoft Azure offers a service called “Azure Application Insights”. As you can expect from it, it makes your requests, responses, perfomance counters, trace logs and other monitored items of your application accessibles on Azure, allowing you to perform data analysis and searching on that data.

You can access it by typing “Application Insights” in the search bar, from the Azure portal home page. The search result will show it.

Right now, we do not have any web applications deployed to the Cloud. First, we should publish one web application to Azure, and then we will be able to use Azure Application Insights.

The Azure App Service service offers a really easy way to publish and monitor our .NET Core app in the Cloud. Visual Studio 2017 enables developers to easily deploy an application on Microsoft Azure.

First, right-click your ASP.NET Core project, and select “Publish…”. A window will be opened, and you will be prompted to select the publish target.

From that list, let’s choose “App Service” and then click “Publish”. The next step will be set the basic information for creating App Service. Information such as App Name and the Resource Group will be asked.

I am going to leave the default values for the form. Click “Create”, and the publish process will get started. Once it is finished, you can go to the Azure Portal, and search for App Service. You will find the App Service we just created. Left-click on it, and a blader menu will be opened. From there, you have access to a whole set of functionalities for the App Service product.

How convenient, the Azure Portal itself recommends us to access Application Insights. Click on the violet alarm, and it will bring you to the Application Insights page. But first, it will ask you if you want to enable it for your application. We want it, of course. Leave every option of the “.NET Core” tab enabled, and click “Apply”.

Once it is finished, we will have an Azure Application Insights service available for our app. From there, you can access several activity logs and even an Application Dashboard.

Easy, huh? You can customize that dashboard, including or removing items as you want. Since alerts are really important for monitoring, it is worth to show how to create them once we have our Application Insights service set up.

We can access the alert window by clicking on the “Alerts” item from the “Configure” category, from our app Application Insights instance page on Azure Portal. You will be prompted to choose under which conditions your alert rule will check on for the threshold value. There are several values from which we can choose, but let’s stick with the “Process CPU”.

Also, we can define “Action Groups”, meaning that we can trigger notifications for our team via email and text messages or automate actions such as function, logic apps and others.

Finish the creation process by clicking on “Create alert rule”.

Once it is created, we will be able to see it on the alert’s list and once the specified threshold is reached, actions will be executed depending on your configuration.