Monitoring a Web Application with Application Insights

Bilge PamukcuBilge Pamukcu
4 min read

Azure Monitor is a powerful toolset that collects and analyzes data from both on-premises and cloud environments. Under the Azure Monitor umbrella, Application Insights enables us to monitor the performance, usage, and availability state of web applications. It comes with investigation, monitoring, usage, and code analysis functionalities. You can easily auto-instrument your applications as well as instrument them with the Application Insights SDK, which is available for various technology stacks.

In this blog post, I'll walk you through a simple auto-instrumentation use case scenario by enabling Application Insights for an App Service-hosted web app, creating an availability test, modifying an alert rule, and triggering the alert. You may need to create and host a website on Azure App Services in your portal environment to follow along with this demo. I followed these steps to perform the demonstration.

  • Open the Web App page. Browse your website by clicking Browse. Copy your site URL for later use.

  • On the Web App page, on the left menu, click Application Insights. Click Turn on Application Insights button.

  • Create a new Application Insights resource by filling up the required fields. You'll need a Log Analytics Workspace to create an Application Insights resource as the workspace provides a context for Azure Monitor resources.

  • Scroll down and under "Instrument your application" section, click .NET and choose Basic in the toggle button. Click on Apply button and complete your Application Insights configuration.

  • Navigate to the Resource Group page. You'll see the Application Insights resource created and listed under the resources. Click the Application Insights resource.

  • On the left menu

    1. Locate and select "Availability."

    2. Here, we will add an availability test to monitor and trace our web application. To do this, click on the "+ Add Classic Test" button.

  • Give your test a name. For the SKU, choose URL Ping. On the URL field, paste the URL of your website. Click Create.

  • You'll see that the new rule gets listed under the Availability Test section. When we create an availability test, it creates a default alert rule for us. Click on the new test and choose "Open Rules (Alerts) page" in the opening menu. This will help us to modify the alert rule by adding an action group to notify us based on the availability (URL Ping) changes.

  • Click on the rule name. On the opening page, click Edit. This will open the edit page of the alert rule.

  • In the Actions section, click Select action groups. This opens the Select action groups page.

  • On the Select action groups page, click + Create action group.

  • Give your action group a name and a display name. Click Notifications tab.

  • On the Notifications tab, choose the "Email/SMS message/Push/Voice" option from the Notification type dropdown list. Type a name for your notification in the Name textbox. Click the pencil symbol and write your email address in the Email box. A notification message will be sent to this email address once an availability status change occurs. Click OK.

  • Click Review + create and complete the action group creation by clicking Create.

  • You'll receive a new email that verifies that you're being to the action group.

  • Click Save in the upper left corner.

  • Open the Application Insights page of the web application. You'll see that the availability states are listed under the Availability Test section.

  • Now, we need to create a negative scenario to test if our availability rule alert notifies us as expected. To create such a failure, open the Web App page and on the Overview page, click Stop.

  • Browse the website URL to verify that the website is no longer running. An "Error 403" message is expected.

  • Navigate back to Application Insights and click the Refresh icon to see if the availability problem is reflected. This may take several minutes to show under the Availability Test section. I see a Failed record appears on the right test details page.

  • I have also received a notification email that provides details about the availability issue, as expected. That concludes this demo.

1
Subscribe to my newsletter

Read articles from Bilge Pamukcu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Bilge Pamukcu
Bilge Pamukcu