MSDN Tutorials

Monitoring Azure Logs

This tutorial will guide you through the process of monitoring logs generated by your Azure resources. Effective log monitoring is crucial for troubleshooting, security analysis, and understanding the operational health of your applications and services.

Prerequisites:

Understanding Azure Monitor Logs

Azure Monitor provides a comprehensive solution for collecting, analyzing, and acting on telemetry from your cloud and on-premises environments. Log data is a key part of this telemetry.

Key Components:

Configuring Diagnostic Settings

To start collecting logs, you need to configure diagnostic settings for your Azure resources.

Steps:

  1. Navigate to your Azure resource in the Azure portal.
  2. In the left-hand menu, under "Monitoring," select "Diagnostic settings."
  3. Click "Add diagnostic setting."
  4. Select the log categories you want to collect (e.g., `AllLogs`, `AuditEvent`, `HTTPProxy`).
  5. Under "Destination details," choose "Send to Log Analytics workspace" and select your target workspace.
  6. Click "Save."

Once configured, logs will start flowing to your selected Log Analytics workspace.

Querying Logs with Kusto Query Language (KQL)

Kusto Query Language (KQL) is used to query data in Log Analytics. Here are some basic examples:

Example 1: View the last 100 security events

SecurityEvent
| take 100

Example 2: View all Azure Activity Logs from the last 24 hours

AzureActivity
| where TimeGenerated > ago(24h)
| project TimeGenerated, OperationName, ResourceGroup, Caller, Status

Example 3: Count successful web server requests

AzureDiagnostics
| where ResourceProvider == "MICROSOFT.WEB"
| where Category == "AppServiceHTTPLogs"
| where HttpStatus >= 200 and HttpStatus < 300
| summarize count() by bin(TimeGenerated, 5m)

You can explore more KQL queries and advanced functionalities in the KQL documentation.

Visualizing Log Data

Azure Monitor allows you to visualize your log data using charts and dashboards.

Alerting on Log Data

Set up alerts to notify you when specific conditions are met based on your log data. This is essential for proactive incident response.

  1. Go to "Alerts" in Azure Monitor.
  2. Click "New alert rule."
  3. Select your subscription and resource group.
  4. Configure the "Condition" using a log search query.
  5. Define "Actions" to be taken (e.g., send an email, trigger an Azure Function).
  6. Complete the alert rule details and create it.

Further Learning