Azure Monitor: metrics, Activity log, alerts
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Day-to-day operations
-
Phase 3: Enterprise architecture
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
Azure Monitor alerts tell you something’s wrong before your users notice. They keep an eye on metrics like CPU, events like “VM deallocated” and logs, and when something matches they send an email, SMS or webhook through an action group.
Out of the box, Azure Monitor collects a lot: platform metrics for every resource and an Activity log entry for every change. Most teams barely use either, and then hear about an outage from a customer on the phone.
You’ll read metrics and the Activity log, build a CPU alert and make it fire, and then close the two alert gaps behind most missed incidents.
| Time | You need | Cost | By the end you can |
|---|---|---|---|
| About 50 minutes | web01, an email address you can read, the CLI | A few US cents: one metric alert rule for an hour; Activity log alerts and the first 1,000 emails a month have no charge | Read metrics and the Activity log, create action groups and alerts, and close common alert gaps |
What it is, in one line
Azure Monitor alerts watch metrics, events and logs, and when a rule matches they tell you through an action group.
In Simple Words
The fire alarm and the visitor book
Every room in a school has a thermometer, and those are your metrics, numbers measured every minute. There’s also a visitor book at the gate that records who came in and what they did, which is the Activity log. An alert is a rule like “if any room is hotter than 50 degrees for five minutes, ring the alarm”, and the action group is the list of people the alarm calls.
But if a room’s thermometer is switched off, it never reads hot and the alarm never rings. That gap is the first break in today’s lab.
Engineer's View
Signals, rules and action groups
- Platform metrics: for most resources these are collected every minute on their own and kept for 93 days. For VMs you get Percentage CPU, Network In/Out, Disk read/write, Available Memory Bytes and more, all measured from the host.
- Activity log: records every control-plane operation (create, update, delete, start, deallocate) with the caller, the time and the status, and keeps it for 90 days. If you want it longer, or want to query it, export it to Log Analytics.
- Alert types: metric alerts (threshold or dynamic), log search alerts (KQL, Lesson 34), Activity log alerts (operations, Service Health, Resource Health), and smart detection.
- Metric alert pieces: a scope, a condition (aggregation, metric, operator, threshold), the window size, how often it’s evaluated, a severity from 0 to 4, and the action groups. Alerts keep state, so they fire once and then resolve when the condition clears.
- Action groups: lists you can reuse, holding notifications (email, SMS, push, voice) and actions (webhook, Logic App, Function, ITSM, Automation runbook). Email is rate-limited to around 100 messages an hour per address.
- Alert processing rules let you mute notifications during planned maintenance, or attach action groups across lots of rules at once.
How it works, step by step
Here’s what happens when web01’s CPU goes over 80%:
- Every minute, the host records Percentage CPU for web01.
- The rule al-web01-cpu checks the average over the last 5 minutes, once a minute.
- Once that average goes above 80, the alert fires at severity 2.
- The action group ag-saat-email sends out the email, and the alert shows up under Azure Monitor, Alerts.
- When the average falls back below 80, the alert resolves and a “Resolved” email follows.
In Azure Monitor alerts, a metric rule can only judge the data it gets. When the VM stops, the metric stops too, and a threshold rule has nothing to compare against.
So good alerting pairs “it’s unhealthy” rules (metrics, logs) with “it’s gone” rules (Activity log, Resource Health, availability).
Hands-on lab: Azure Monitor alerts for web01
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
Set your email address and load the IDs:
$mail = 'you@example.com' # use your own address
$sub = az account show --query id -o tsv
$web01 = az vm show --resource-group rg-saat-vms --name web01 --query id -o tsv
az vm start --resource-group rg-saat-vms --name web011Create an action group
Run this:
az monitor action-group create --resource-group rg-saat-core --name ag-saat-email --short-name saatmail --action email admin $mail --tags course=saatvedha-azure lesson=31 keep=true -o none
$ag = az monitor action-group show --resource-group rg-saat-core --name ag-saat-email --query id -o tsv
az monitor action-group show --resource-group rg-saat-core --name ag-saat-email --query "emailReceivers[].{name:name, email:emailAddress, status:status}" -o tableYou should see something like this:
Name Email Status
------ --------------- --------
admin you@example.com EnabledYou’ll also get an email telling you you’ve been added to the action group. Keep this group, because the next lessons use it.
2Read web01’s metrics
Run this:
az monitor metrics list --resource $web01 --metric "Percentage CPU" --interval PT5M --aggregation Average --offset 1h --query "value[0].timeseries[0].data[-3:].{time:timeStamp, avg:average}" -o tableYou should see something like this:
Time Avg
------------------------- ------
2026-10-20T17:35:00+00:00 1.62
2026-10-20T17:40:00+00:00 0.88
2026-10-20T17:45:00+00:00 0.913Read the Activity log
Look at what changed on your VMs in the last two hours, and who changed it:
az monitor activity-log list --resource-group rg-saat-vms --offset 2h --query "[?status.value=='Succeeded'].{time:eventTimestamp, operation:operationName.value, caller:caller}" -o tableYou should see something like this:
Time Operation Caller
-------------------------------- ---------------------------------------------- ----------------
2026-10-20T17:31:12.4400000Z Microsoft.Compute/virtualMachines/start/action you@example.comNote down the exact format of the operation name, because you’ll need it in Break It.
4Create a CPU alert and make it fire
Create the rule, and then keep both vCPUs busy for 8 minutes:
az monitor metrics alert create --resource-group rg-saat-vms --name al-web01-cpu --scopes $web01 --condition "avg Percentage CPU > 80" --window-size 5m --evaluation-frequency 1m --severity 2 --action $ag --description "web01 CPU above 80 percent" -o none
az vm run-command invoke --resource-group rg-saat-vms --name web01 --command-id RunShellScript --scripts 'for i in 1 2; do nohup timeout 480 yes >/dev/null 2>&1 & done; echo started' --query "value[0].message" -o tsvGive it about 7 minutes and then check the metric:
az monitor metrics list --resource $web01 --metric "Percentage CPU" --interval PT1M --aggregation Average --offset 10m --query "value[0].timeseries[0].data[-2:].{time:timeStamp, avg:average}" -o tableYou should see something like this, and an email:
Time Avg
------------------------- ------
2026-10-20T17:58:00+00:00 99.71
2026-10-20T17:59:00+00:00 99.68The email subject starts with “Fired:Sev2 Azure Monitor Alert al-web01-cpu”, and around 5 minutes after the load stops you’ll get a “Resolved” email as well.


✅ Checkpoint: ag-saat-email exists, you read metrics and the Activity log, and al-web01-cpu fired and then resolved.
Break It, Then Fix It
Both of these Azure Monitor alerts gaps are silent. There’s no error, you just don’t get the email when you need it.
1Break it: the server is down and nobody hears
Deallocate web01, the way an accident or a rogue script might, and wait 10 minutes:
az vm deallocate --resource-group rg-saat-vms --name web01
az monitor metrics list --resource $web01 --metric "Percentage CPU" --interval PT1M --aggregation Average --offset 10m --query "value[0].timeseries[0].data[-2:].{time:timeStamp, avg:average}" -o tableYou should see something like this:
Time Avg
------------------------- -----
2026-10-20T18:20:00+00:00
2026-10-20T18:21:00+00:00There are no values, so the CPU rule has nothing to compare and stays quiet. The only CPU alert you have can’t tell “idle” apart from “gone”.
Fix it: add an Activity log alert for deallocation, and test it:
az monitor activity-log alert create --resource-group rg-saat-core --name al-vm-deallocate --scope "/subscriptions/$sub/resourceGroups/rg-saat-vms" --condition "category=Administrative and operationName=Microsoft.Compute/virtualMachines/deallocate/action" --action-group $ag --description "web01 or win01 deallocated" -o none
az vm start --resource-group rg-saat-vms --name web01
az vm deallocate --resource-group rg-saat-vms --name web01Within a few minutes an email arrives for al-vm-deallocate, naming the VM and whoever did it. For crashes that nobody caused, you’d use Resource Health alerts and the VM availability metric.
2Break it: the Activity log alert that never fires
Add an alert for restarts, typing the operation name from memory, and then restart win01:
az monitor activity-log alert create --resource-group rg-saat-core --name al-vm-restart --scope "/subscriptions/$sub/resourceGroups/rg-saat-vms" --condition "category=Administrative and operationName=Microsoft.Compute/virtualMachines/restart" --action-group $ag --description "web01 or win01 restarted" -o none
az vm start --resource-group rg-saat-vms --name win01
az vm restart --resource-group rg-saat-vms --name win01Wait 10 minutes and no email comes. Azure created the rule without complaining, but the real operation name ends in /action, so the condition never matches.
Fix it: copy the name from a real event, and then correct the rule:
az monitor activity-log list --resource-group rg-saat-vms --offset 1h --query "[?contains(operationName.value, 'restart')].operationName.value | [0]" -o tsv
az monitor activity-log alert delete --resource-group rg-saat-core --name al-vm-restart
az monitor activity-log alert create --resource-group rg-saat-core --name al-vm-restart --scope "/subscriptions/$sub/resourceGroups/rg-saat-vms" --condition "category=Administrative and operationName=Microsoft.Compute/virtualMachines/restart/action" --action-group $ag --description "web01 or win01 restarted" -o none
az vm restart --resource-group rg-saat-vms --name win01The first command prints this, and once you restart again an email arrives:
Microsoft.Compute/virtualMachines/restart/actionTo clean up, keep the action group, delete the rules and stop win01:
az monitor metrics alert delete --resource-group rg-saat-vms --name al-web01-cpu
az monitor activity-log alert delete --resource-group rg-saat-core --name al-vm-deallocate
az monitor activity-log alert delete --resource-group rg-saat-core --name al-vm-restart
az vm deallocate --resource-group rg-saat-vms --name win01
az monitor action-group list --resource-group rg-saat-core --query "[].name" -o tsvYou should see this:
ag-saat-email
✅ Checkpoint: You closed a “VM gone” gap and fixed a rule that could never match. Only ag-saat-email stays, and both VMs are deallocated.
This happened at work
The weekend nobody was paged
An e-commerce company had CPU, memory and disk alerts set up on every web server. One Saturday night, a cost-saving script deallocated the entire web tier by mistake, and the site stayed down for 9 hours without one alert firing.
Every rule they had was watching a metric from a running VM, so once the VMs were deallocated the metrics stopped coming. The on-call engineer only found out on Sunday morning, from a customer’s tweet.
What they changed: they added Activity log alerts for deallocate, delete and power off on every production resource group, Resource Health alerts for unplanned downtime, and an availability test that loads the home page every 5 minutes from three regions. The cost script now refuses to touch anything tagged env=prod.
Common mistakes and troubleshooting
| Mistake | What you see | What to do |
|---|---|---|
| Only metric alerts | Silence when the VM is stopped or deleted | Add Activity log, Resource Health and availability alerts. |
| Operation name typed from memory | Activity log alert never fires | Copy operationName from a real event. |
| Thresholds too low | Alerts all day, people stop reading them | Tune thresholds; use dynamic thresholds. |
| One person in the action group | Alert missed on leave or at night | Use a team mailbox, SMS or an on-call tool. |
| No alerts during maintenance planning | Noise or missed real issues | Use alert processing rules for planned windows. |
| Short window with spiky metrics | Fires and resolves repeatedly | Use a longer window or more failing periods. |
Interview questions
Click any question to open it. They’re worded the way an interviewer would ask them, and under each one you’ll find why they ask it and one way you could answer in your own words.
Fresher level
1. What is the difference between metrics and logs in Azure Monitor?
Why they ask this: To see if you know the basic idea.
How you might answer: Metrics are numbers sampled at regular intervals. They’re light and fast, so they’re good for thresholds and charts. Logs are detailed records kept in Log Analytics, and you query them with KQL when you’re investigating or need a complex condition.
2. What is an action group?
Why they ask this: It’s one of the building blocks.
How you might answer: It’s a list of notifications and actions you can reuse, like email, SMS, webhooks or runbooks, and alert rules call it when they fire.
3. What does the Activity log record?
Why they ask this: They want to see you understand the control plane.
How you might answer: It records every management operation on Azure resources: who did what, when, on which resource, and whether it worked. It keeps 90 days unless you export it.
2–5 years experience
4. A VM went down but no alert fired. Why, and what would you add?
Why they ask this: It’s a real gap and they want to know you’ve seen it.
How you might answer: Metric alerts need data, and a stopped VM doesn’t send any. I’d add Activity log alerts for deallocate and delete, Resource Health alerts for platform problems, and an availability or heartbeat check for the app itself.
5. What’s the difference between static and dynamic thresholds?
Why they ask this: They want to see you know how to tune alerts.
How you might answer: A static threshold compares against a fixed number. A dynamic one learns what’s normal for the metric by time of day and day of week and alerts when it moves away from that, which cuts down noise on metrics that swing a lot.
6. How would you stop alerts during a planned maintenance window?
Why they ask this: They’re checking you know about alert processing rules.
How you might answer: I’d create an alert processing rule scoped to the resources involved that suppresses notifications during the window. The alerts still fire and get recorded, so the history stays complete.
Senior level
7. How would you design alerting for a production platform?
Why they ask this: They want to hear structure, not a list of metrics.
How you might answer: I’d start from what users feel, so availability tests and the key app metrics. After that comes infrastructure health with metrics and Resource Health, change awareness with Activity log alerts, and log alerts for failure patterns we already know. Severities map to on-call routes, it’s all deployed as code, and every alert has a runbook.
8. How do you manage alert rules across hundreds of resources?
Why they ask this: They’re checking scale.
How you might answer: I’d use multi-resource metric alerts scoped to a subscription or resource group, Azure Policy or the built-in recommended alerts to roll the rules out, Bicep to keep them consistent, and alert processing rules to route by tag.
9. How do you avoid alert fatigue?
Why they ask this: They want to hear your judgement.
How you might answer: Every alert has to be actionable and have an owner. I’d review the noisy ones every month, use dynamic thresholds and longer windows, group alerts that belong together, and delete any rule nobody acts on.
Quick quiz
Q1. How long are platform metrics kept by default?
- 7 days
- 30 days
- 93 days
- 1 year
Show answer
C — Platform metrics are kept for 93 days.
Q2. What does an action group do?
- Stores metrics
- Lists who and what to notify
- Creates VMs
- Runs KQL
Show answer
B — Action groups hold notifications and actions.
Q3. A VM is deallocated. Does its CPU alert fire?
- Yes, at 0%
- No, there is no data
- Only on weekends
- It deletes the VM
Show answer
B — No metric data means no threshold breach.
Q4. Which alert catches “VM deallocated”?
- Metric alert on CPU
- Activity log alert
- Smart detection
- Storage alert
Show answer
B — Deallocation is a control-plane operation in the Activity log.
Q5. An Activity log alert uses “…/restart” without /action. Result?
- Works
- Never matches
- Fires twice
- Error on create
Show answer
B — The condition must match the exact operation name.
Quick recap
You can now see what your resources are up to and set up Azure Monitor alerts that tell you when it matters.
Before moving on, open Azure Monitor, Alerts in the portal and look through the history of al-web01-cpu. You’ll see each fired and resolved event with its time, its severity and the value that crossed the line. Real teams look at this history first after an incident, to check whether the right alert fired, whether it reached the right people and how long it took someone to act.
- Metrics are automatic; the Activity log records every change.
- Metric alerts need data; add “it’s gone” alerts too.
- Action groups are reusable notification lists.
- Copy Activity log operation names from real events.
- Every alert should be actionable and owned.
Next lesson
Lesson 32: Azure Monitor Agent and data collection rules → Next, you install the Azure Monitor Agent and start sending VM logs and performance data to Log Analytics.
Further reading: Azure Monitor alerts
Want to go deeper into Azure Monitor alerts? Microsoft’s Overview of Azure Monitor alerts and Action groups are good next reads, and the full plan for this course is on the Azure Cloud Administration course page.
