Monitor Your Azure Web App
This tutorial guides you through setting up and using Azure Monitor to gain insights into the performance, availability, and health of your Azure Web App. Learn how to collect metrics, analyze logs, and set up alerts.
1. Overview of Azure Monitor for Web Apps
Azure Monitor is a comprehensive solution for collecting, analyzing, and acting on telemetry from your cloud and on-premises environments. For Azure Web Apps, it provides deep visibility into:
- Performance Metrics: CPU usage, memory, HTTP requests, data in/out, etc.
- Availability: Uptime and responsiveness.
- Application Logs: Errors, warnings, and custom logging.
- Resource Health: Issues with the underlying Azure infrastructure.
2. Enabling Diagnostic Settings
To collect detailed logs and metrics, you need to configure diagnostic settings for your Web App. This pushes logs to various destinations like Log Analytics workspaces, Storage Accounts, or Event Hubs.
Navigate to your Web App
In the Azure portal, search for and select your Web App.
Access Diagnostic Settings
Under the "Monitoring" section in the Web App's menu, select "Diagnostic settings".
Add Diagnostic Setting
Click on "+ Add diagnostic setting".
- Name: Provide a descriptive name (e.g., "WebAppMonitoringLogs").
- Categories: Select the logs and metrics you want to collect. Common choices include:
- `AppServiceHTTPLogs`
- `AppServiceAppLogs` (for application logging)
- `AppServiceConsoleLogs`
- `AppServiceAuditLogs`
- `AllMetrics`
- Destination details: Choose where to send the data. For powerful analysis, select "Send to Log Analytics workspace" and choose or create a workspace.
Save Settings
Click "Save". It may take a few minutes for the settings to take effect.
3. Analyzing Metrics in Azure Monitor
Azure Monitor provides a rich set of metrics that offer real-time insights into your Web App's performance.
Access Metrics Blade
From your Web App's menu, under "Monitoring", select "Metrics".
Select Metrics and Visualizations
You can:
- Choose from a wide range of metrics (e.g., "CPU Time", "Http 5xx", "Requests", "Memory Working Set").
- Apply splitting by dimension (e.g., instance name) to see performance per instance.
- Change the aggregation type (Average, Sum, Max, Min).
- Visualize the data as line charts, bar charts, or scatter plots.
- Pin charts to your Azure Dashboard for quick access.
Set Time Range
Adjust the time range to view performance over different periods (e.g., last hour, last 24 hours, custom range).
4. Querying Logs with Log Analytics
Log Analytics allows you to run powerful queries against your collected logs using Kusto Query Language (KQL).
Access Log Analytics
Navigate to your Log Analytics workspace (the one configured in diagnostic settings) and select "Logs".
Run Sample Queries
In the query editor, you can run queries to analyze your Web App's data. Here are a few examples:
Explore Tables
Familiarize yourself with the tables available in your Log Analytics workspace, particularly those starting with `AppService` or `AzureMetrics`.
5. Setting Up Alerts
Proactive alerting helps you respond to issues before they impact your users.
Navigate to Alerts
From your Web App's menu, under "Monitoring", select "Alerts". Then click "+ Create" > "Alert rule".
Configure Alert Rule
- Scope: Ensure your Web App is selected.
- Condition: Click "Add condition". Choose a signal (metric or log search).
- For metrics: e.g., "CPU Time" > 80% over 15 minutes.
- For logs: Write a KQL query that returns results when a condition is met. e.g., count of HTTP 5xx errors > 10 in 5 minutes.
- Actions: Define what happens when the alert triggers (e.g., send an email, trigger an Azure Function, notify an ITSM tool). Create or select an Action Group.
- Details: Provide a name, description, severity, and resource group for the alert rule.
Create Alert Rule
Click "Create alert rule".
Conclusion
By leveraging Azure Monitor, you can gain deep visibility into your Azure Web App's performance and health. Regularly review metrics, analyze logs, and configure alerts to ensure your application remains available and performs optimally.
Explore further to learn about Application Insights for application-level performance monitoring and distributed tracing.