Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 41 of 47
❮Prev Next❯

Azure Monitor Metrics and Diagnostic Settings

Module 5: Monitor & Backup ⏱ 11 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    Platform metrics are numbers every Azure resource sends to Azure Monitor about once a minute, with no setup, and Azure keeps them for 93 days. Resource logs (such as StorageRead or Key Vault AuditEvent) aren't kept at all until you create a diagnostic setting that sends them to a Log Analytics workspace, a storage account, Event Hubs or a partner solution. The activity log records control-plane actions (who created, changed or deleted what) for 90 days. A VM has no resource logs: its guest OS data comes through the Azure Monitor Agent and a data collection rule.

    Simulate it » No Azure account needed

    Exam objective: 5.1.1 Interpret metrics in Azure Monitor. 5.1.2 Configure log settings in Azure Monitor. (Skills measured as of April 17, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    Azure portal: Read a metric, then add a diagnostic setting Read a metric, then route blob logs to a workspace.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    Open the storage account. Platform metrics are already being collected, so start with <strong>Monitoring → Metrics</strong>.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Open the storage account. Platform metrics are already being collected, so start with Monitoring → Metrics.
    2. Pick the Transactions metric with Sum. Apply splitting by ResponseType shows the spike is mostly AuthorizationError. Metrics are kept 93 days, but they don’t say who called.
    3. Open Diagnostic settings. Resource logs aren’t kept until you add one, and for storage you add it on the blob service.
    4. Name it, tick allLogs and Transaction, and choose Send to Log Analytics workspace. You could also archive to a storage account or stream to an event hub in the same setting.
    5. Now check who changed what. Search for Monitor.
    6. Type monitor in the search bar and pick Monitor under Services.
    7. The activity log covers control-plane actions for the whole subscription: here Ben listed the keys and deleted a VM. It keeps 90 days. Export Activity Logs opens a subscription diagnostic setting to keep it longer in the workspace.

    🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.

    😟 THE PROBLEM

    A storage account throws 403 errors and nobody knows who is calling it.

    😊 THE SOLUTION

    Read the metrics, then route the blob logs to a workspace with a diagnostic setting.

    • Only a vague spike✓ Metrics split by response type
    • Logs thrown away✓ A diagnostic setting on the blob service
    • Who deleted the VM?✓ The activity log
    🛠️ Solved with: Metrics and diagnostic settings

    Start with a question

    Your car's dashboard shows speed and fuel all the time. So why doesn't it remember who borrowed it last Tuesday?

    The dashboard gives you numbers the moment you start the engine: speed, fuel, temperature. Nobody had to switch that on. But if you want a record of every trip, who drove and where they went, you have to fit a trip recorder and decide where its data goes.

    Azure works the same way. Platform metrics are the dashboard: CPU, transactions and availability arrive on their own. Resource logs are the trip recorder: they’re only kept once you add a diagnostic setting and choose where they go. And the activity log is the car’s service book: who changed the car itself.

    Explain it like I’m 10

    The technical explanation

    Azure Monitor collects three kinds of data from Azure resources without you installing anything, but only one of them is kept by default.

    DataWhat it isCollected by default?KeptWhere you see it
    Platform metricsNumbers sampled about once a minute (Percentage CPU, Transactions, Availability)Yes93 daysMetrics explorer, metric alerts
    Resource logsData-plane records from inside the resource (StorageRead, AuditEvent, NetworkSecurityGroupEvent)NoWherever you send themLog Analytics, storage, Event Hubs
    Activity logControl-plane operations for the subscription: create, update, delete, role assignments, Service HealthYes90 daysMonitor > Activity log, every resource’s Activity log blade

    Interpret metrics in Metrics explorer

    Open any resource, then Monitoring > Metrics (or Monitor > Metrics and pick a scope). Each chart has:

    • a metric namespace and metric, such as Account / Transactions on a storage account,
    • an aggregation: Average, Min, Max, Sum or Count. Average CPU and Max CPU can tell very different stories,
    • Add filter to keep one dimension value (only ResponseType = AuthorizationError),
    • Apply splitting to draw one line per dimension value (one line per response type, per API name, per VM instance),
    • a time range and time granularity. One chart can show up to 30 days, and you can pan back through the 93 days kept.

    From the same chart you can Save to dashboard or select New alert rule. The CLI equivalent reads the same data:

    az monitor metrics list \
      --resource /subscriptions/<sub>/resourceGroups/rg-ops-mon/providers/Microsoft.Compute/virtualMachines/vm-web01 \
      --metric "Percentage CPU" --interval PT1M --aggregation Average -o table
    
    az monitor metrics list-definitions --resource <resource id> -o table   # what metrics exist

    Configure log settings with diagnostic settings

    A diagnostic setting is a rule on one resource. It has a name, the log categories or category groups to send (allLogs or audit, which also pick up categories Microsoft adds later), optionally AllMetrics, and one or more destinations:

    DestinationPick it whenNotes
    Log Analytics workspaceYou want to query with KQL, build workbooks or create log search alertsChoose Azure diagnostics (one shared table) or Resource specific (one table per category, recommended where offered)
    Storage accountYou need a cheap archive for auditsMust be in the same region as the resource. Use lifecycle rules for retention
    Event HubsYou stream to a SIEM or a third-party toolNeeds a namespace and an authorization rule
    Partner solutionYou use an Azure Native ISV service such as Datadog or ElasticConfigured from the partner resource

    One setting can use several destinations at once, and a resource can have up to five diagnostic settings. Logs flow from the moment you save; nothing is backfilled.

    Portal path: resource > Monitoring > Diagnostic settings > + Add diagnostic setting. For a storage account you first pick the blob, file, queue or table service, because that’s where StorageRead, StorageWrite and StorageDelete live. The account level only offers the Transaction metrics.

    az monitor diagnostic-settings categories list \
      --resource <storage id>/blobServices/default -o table
    
    az monitor diagnostic-settings create --name diag-blob \
      --resource <storage id>/blobServices/default \
      --workspace law-contoso-ops \
      --logs '[{"categoryGroup":"allLogs","enabled":true}]' \
      --metrics '[{"category":"Transaction","enabled":true}]'
    $log = New-AzDiagnosticSettingLogSettingsObject -CategoryGroup allLogs -Enabled $true
    New-AzDiagnosticSetting -Name diag-blob -ResourceId "$storageId/blobServices/default" `
      -WorkspaceId $workspaceId -Log $log

    Virtual machines are different

    A VM has no resource log categories. A diagnostic setting on a VM can only send platform metrics. Windows event logs, Syslog and guest performance counters come from the Azure Monitor Agent (AMA), and a data collection rule (DCR) says what to collect and which workspace to send it to. The old Log Analytics agent (MMA) and the Windows Azure Diagnostics extension are retired, so don’t pick them in a new design.

    The activity log

    The activity log is one per subscription and records control-plane events: someone created a VM, changed an NSG rule, assigned a role, listed storage keys, or Azure posted a Service Health event. It doesn’t record data-plane actions like reading a blob. Filter it by resource group, resource, operation, caller and time span in Monitor > Activity log, or from the CLI:

    az monitor activity-log list -g rg-ops-mon --offset 1h -o table
    az monitor activity-log list --caller ben@contoso.com --offset 7d

    To keep it longer than 90 days or join it with other logs, select Export Activity Logs, which creates a subscription diagnostic setting (az monitor diagnostic-settings subscription create). In a workspace it lands in the AzureActivity table.

    Architect level Resource-specific tables, costs and retention

    When you send logs to a workspace, resource-specific mode writes each category to its own table (StorageBlobLogs, AzureBackup tables, AppServiceHTTPLogs). Queries are faster, columns are typed and you can set retention per table. The older Azure diagnostics mode puts everything into the wide AzureDiagnostics table. Some services only support one mode; Azure Backup reports need resource-specific.

    Workspaces charge per GB ingested (around $2.30 per GB on pay-as-you-go for Analytics logs, illustrative) and include 31 days of retention. Interactive retention goes up to two years, and long-term retention up to 12 years at a lower price. For noisy, rarely queried data, look at the Basic or Auxiliary table plans, or archive to storage instead.

    Real-world business scenario

    Healthcare manufacturing

    Contoso Pharma (fictional)

    The problem
    A storage account holding batch records showed a spike in failed requests on the Transactions metric, and an auditor asked who had read the files in the last month. Nobody could answer: no diagnostic settings existed.
    What they used
    Metrics explorer with splitting by response type showed the spike was authorization errors. The admin team added a diagnostic setting on the blob service with allLogs, sending to a Log Analytics workspace for KQL and to a same-region storage account with a seven-year lifecycle rule. A subscription diagnostic setting exported the activity log to the same workspace.
    Why that choice
    Metrics told them something was wrong within minutes. Resource logs told them who and from where. The activity log covered every configuration change.
    The result
    The next audit request took one KQL query. The failures turned out to be an old SAS token in a partner script, which was rotated the same day.

    When to use it and when not to

    ✓ Use it when…

    • You need to see how a resource is behaving right now or over the last 93 days: use Metrics explorer.
    • You need to know who accessed data inside a resource: add a diagnostic setting for its resource logs.
    • You need to know who changed or deleted a resource: read the activity log, and export it for longer retention.

    ✕ Think twice when…

    • Sending every log category from every resource to a workspace "just in case". Pick categories you will query, or archive to storage.
    • Using a diagnostic setting for guest OS data on a VM. Use the Azure Monitor Agent and a data collection rule.
    • Relying on the activity log for data-plane auditing such as blob reads.

    ↔ Alternatives to consider

    • Azure Policy (DeployIfNotExists) to create diagnostic settings on every new resource automatically.
    • VM insights to switch on the Azure Monitor Agent and a ready-made data collection rule.
    • Storage account archive instead of a workspace for logs you keep only for compliance.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    You need to review the average Percentage CPU of a virtual machine for each hour over the last 14 days. No monitoring configuration has been performed on the virtual machine. What should you use?

    Question 2

    Question 2 of 5

    A storage account named stcontoso1 receives many failed requests. You must chart the number of failed transactions by response type for the last 24 hours. What should you do in Metrics explorer?

    Question 3

    Question 3 of 5 · Select 2

    You plan to collect the StorageRead and StorageWrite logs of an Azure Storage account and query them by using KQL. The solution must minimize administrative effort. Which two actions should you perform? Each correct answer presents part of the solution.

    Question 4

    Question 4 of 5

    You must retain the activity log of an Azure subscription for two years and query it together with other logs. What should you configure?

    Question 5

    Question 5 of 5

    You need to collect Windows event logs from an Azure virtual machine named VM1 and send them to a Log Analytics workspace. What should you do?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner What's the difference between a metric and a log in Azure Monitor?

    Model answer

    A metric is a number sampled over time, like CPU percentage every minute. It's cheap, fast and great for charts and threshold alerts. A log is a record with lots of fields, like "GetBlob on invoice-12.pdf from 203.0.113.50 returned 403". Logs answer who, what and why, and you query them with KQL in a Log Analytics workspace.

    Intermediate A developer says the storage account's logs show nothing. What's your first check?

    Model answer

    Whether there's a diagnostic setting at all, and whether it's on the right level. Storage resource logs live on the blob, file, queue and table services, not on the account itself. So I'd open Diagnostic settings, pick the blob service, tick allLogs and send it to the workspace. Logs only start flowing from that moment; there's no backfill.

    Experienced developer How would you keep the activity log for two years?

    Model answer

    The activity log itself keeps 90 days. I'd add a subscription-level diagnostic setting that sends the categories I need (Administrative, Security, Policy, ServiceHealth and so on) to a Log Analytics workspace and set that table's retention to two years, or archive it to a storage account if nobody needs to query it often.

    Scenario The security team wants Key Vault access logs in their SIEM in real time and the auditors want seven years of copies. How do you do both?

    Model answer

    One diagnostic setting on the vault with AuditEvent, sending to Event Hubs for the SIEM and to a storage account with a lifecycle rule for the long-term copy. I could add the workspace in the same setting too. A resource can have up to five diagnostic settings, but one with several destinations is usually enough.

    Quick revision

    Key points

    • Platform metrics are automatic and kept 93 days. Metrics explorer charts them with aggregation, filtering and splitting.
    • Resource logs need a diagnostic setting. Destinations are a Log Analytics workspace, a storage account, Event Hubs or a partner solution.
    • Storage logs are set on each service (blobServices/default and so on), not on the account.
    • The activity log is subscription-wide, control plane only, and kept 90 days. Export it with a subscription diagnostic setting.
    • VMs have no resource log categories. Use the Azure Monitor Agent with a data collection rule for guest OS data.

    Important terminology

    Platform metrics
    Numeric values that Azure resources send to Azure Monitor automatically, about once a minute, kept for 93 days.
    Metrics explorer
    The Metrics blade where you chart a metric with an aggregation, filters and splitting.
    Resource logs
    Data-plane logs from inside a resource, such as blob reads or Key Vault secret gets. Not collected until a diagnostic setting routes them.
    Activity log
    The subscription-level log of control-plane operations (create, update, delete, role assignments), kept 90 days.
    Diagnostic setting
    A rule on a resource that sends chosen log categories and metrics to a Log Analytics workspace, storage account, event hub or partner solution.
    Category group
    A shortcut in a diagnostic setting, allLogs or audit, that picks up new log categories automatically.
    Resource-specific mode
    A diagnostic setting option that writes logs to one table per category instead of the shared AzureDiagnostics table.
    Azure Monitor Agent
    The agent that collects guest OS logs and performance counters from VMs according to data collection rules.

    Common mistakes

    • Expecting resource logs from before the diagnostic setting existed. Collection starts when you save it.
    • Adding the diagnostic setting on the storage account and wondering why StorageRead never appears.
    • Thinking the activity log shows data-plane actions like reading a blob. It doesn't.

    Exam tips

    • "Query the logs with KQL" = destination Log Analytics workspace. "Cheapest long-term archive" = storage account. "Stream to a third-party SIEM" = Event Hubs.
    • "Who deleted the VM?" = activity log. "Who read the blob?" = resource logs through a diagnostic setting.
    • The storage account used as a destination must be in the same region as the monitored resource.

    Five quick revision questions

    1. 1.How long are platform metrics kept?Show

      93 days.

    2. 2.How long does the activity log keep events?Show

      90 days.

    3. 3.Name the four diagnostic setting destination types.Show

      Log Analytics workspace, storage account, Event Hubs, partner solution.

    4. 4.What collects guest OS logs from a VM?Show

      The Azure Monitor Agent with a data collection rule.

    5. 5.How many diagnostic settings can one resource have?Show

      Up to five.

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Query Azure Monitor Logs with KQL

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.