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.

1

Navigate to your Web App

In the Azure portal, search for and select your Web App.

2

Access Diagnostic Settings

Under the "Monitoring" section in the Web App's menu, select "Diagnostic settings".

3

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.
4

Save Settings

Click "Save". It may take a few minutes for the settings to take effect.

Important: Sending logs to a Log Analytics workspace is highly recommended for advanced querying and analysis using Kusto Query Language (KQL).

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.

1

Access Metrics Blade

From your Web App's menu, under "Monitoring", select "Metrics".

2

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.
3

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).

1

Access Log Analytics

Navigate to your Log Analytics workspace (the one configured in diagnostic settings) and select "Logs".

2

Run Sample Queries

In the query editor, you can run queries to analyze your Web App's data. Here are a few examples:

// All HTTP requests to your Web App in the last 24 hours AppServiceHTTPLogs | where TimeGenerated > ago(24h) | project TimeGenerated, Url, Method, StatusCode, Duration | order by TimeGenerated desc
// Application logs from your Web App AppServiceAppLogs | where TimeGenerated > ago(1h) | where Level == "Error" | project TimeGenerated, Message, Level | order by TimeGenerated desc
// CPU usage trends for your Web App AzureMetrics | where ResourceProvider == "MICROSOFT.WEB" and ResourceKind == "WEBSITES" | where MetricName == "CPUTime" | where TimeGenerated > ago(6h) | summarize avg(Message) by bin(TimeGenerated, 5m), Computer // Computer is the instance name | order by TimeGenerated asc
3

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.

1

Navigate to Alerts

From your Web App's menu, under "Monitoring", select "Alerts". Then click "+ Create" > "Alert rule".

2

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.
3

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.