Implement Real-Time Monitoring with Azure Monitor
In this lab, you will implement real-time monitoring for a web application using Azure Monitor and Application Insights. This will help you gain insights into application performance, detect anomalies, and ensure the reliability of your services.
You will learn how to:
- Create a sample web app.
- Enable and configure Azure Monitor and Application Insights.
- Create custom dashboards to visualize application metrics.
- Set up alerts to notify stakeholders of performance anomalies.
- Analyze performance data for potential improvements.
This lab takes approximately 20 minutes to complete.
Before you start
To complete the lab, you need:
- An active Azure subscription. If you don't have one, you can create a free account at Azure Free Account.
- Basic knowledge of monitoring and observability concepts.
- Basic understanding of Azure services.
Create a sample web application
In this exercise, you will create a sample web application in Azure App Service and enable Application Insights for monitoring.
Create an Azure Web App
- Open the Azure portal.
- In the Search bar, type App Services and select it.
- Select + Create and select Web App.
- In the Basics tab:
- Subscription: Select your Azure subscription.
- Resource Group: Select Create new, enter
monitoringlab-rg
, and select OK. - Name: Enter a unique name, such as
monitoringlab-webapp
. - Publish: Select Code.
- Runtime stack: Choose .NET 8 (LTS).
- Region: Select a region close to you.
- Select Review + create, then select Create.
- Wait for deployment to complete, then select Go to resource.
- In the Overview tab, select the URL to verify the web app is running.
Verify Application Insights
-
In the Web App resource, in the left panel, expand the Monitoring section and select Application Insights.
-
Application Insights is already enabled for this web app. Select the link to open the Application Insights resource.
-
In the Application Insights resource, select Application Dashboard to view the performance data the default dashboard provided.
Note: The dashboard may take a few moments to fully load and display all performance data. Wait for the dashboard to completely render before proceeding to ensure optimal experience in subsequent exercises.
Configure Azure Monitor and dashboards
Access Azure Monitor
- In the Azure portal, search for Monitor and select Monitor.
- Select Metrics in the left panel.
- In the Scope section, select the web app under the subscription and resource group where you deployed the web app.
- Select Apply and observe the metrics available for the web app.
Add key metrics to the dashboard
- In the Scope section, select your Web App (monitoringlab-webapp).
- Under Metric, choose Response Time.
- Set the Aggregation to Average and select + Add metric.
- Repeat the process for additional metrics:
- CPU Time (Count)
- Requests (Average)
- In the metrics chart area, select the Pin to dashboard button (pin icon) in the top-right corner of the chart.
- In the Pin to dashboard dialog that appears:
- Select New to create a new dashboard
- Enter a dashboard name:
MonitoringLab Dashboard
- Choose Shared for dashboard type
- Select the appropriate subscription
- Select Create and pin
- After the dashboard is created and the metrics are pinned, select Save in the top menu to save the dashboard.
- Navigate to the dashboard by selecting the Dashboard icon in the left panel of the Azure portal, or search for "Dashboard" in the top search bar.
- Select your newly created MonitoringLab Dashboard from the dashboard list.
- Verify the metrics are displayed on the dashboard and are updating in real-time.
Create alerts
Define alert conditions and actions
-
In Azure Monitor, select Alerts.
-
Select + Create and select Alert rule.
-
Under Scope, select your Web App (monitoringlab-webapp) and select Apply.
-
Under Condition, select the Signal name field and select Response Time.
-
Configure the alert rule:
- Threshold type: Dynamic
- Aggregation type: Average
- Value is: Greater or Less than
- Threshold Sensitivity: High
- When to evaluate: Check every 1 minutes and look back at 5 minutes.
-
Under Actions, select Use quick actions.
-
Enter:
- Action group name: WebAppMonitoringAlerts
- Display name: WebAlert
- Email: Enter your email address.
-
Select Save.
-
Select Next: Details.
-
Enter a Name
WebAppResponseTimeAlert
and select Severity level Verbose. -
Select Review + create and then Create.
Note: Your alert rule is now created and will trigger an email notification when the response time exceeds the threshold. You can force the alert to trigger by sending a large number of requests to the web app. For example, you can use Azure Load testing or a tool like Apache JMeter.
-
Go back to the Azure Monitor > Alerts.
-
Select Alert rules and you should see the alert rule you created.
Analyze performance data
Review Collected Metrics
- Go to Application Insights in the Azure portal.
- Select Application Dashboard.
- Select the Performance tile to analyze server response times and load. You can also view the number of requests and failed requests.
- Select Analyze with Workbooks and select Performance Counter Analysis.
- Select Workbooks.
- Select the workbook Performance Analysis under Performance.
- You can see the performance data for the web app.
Note: You can customize the workbook to include additional metrics and filters.
Clean up resources
Now that you finished the exercise, you should delete the cloud resources you created to avoid unnecessary resource usage.
- In your browser navigate to the Azure portal https://portal.azure.com; signing in with your Azure credentials if prompted.
- Navigate to the resource group you created and view the contents of the resources used in this exercise.
- On the toolbar, select Delete resource group.
- Enter the resource group name and confirm that you want to delete it.
CAUTION: Deleting a resource group deletes all resources contained within it. If you chose an existing resource group for this exercise, any existing resources outside the scope of this exercise will also be deleted.