Skip to main content

Building Azure Monitor Alerts and Action Groups

Learn to configure Azure Monitor alert rules and Action Groups so the right people are notified before a problem becomes an outage.

Overview and What You Will Learn

An Azure Monitor alert has two parts: an alert rule that decides when something is wrong, and an Action Group that decides who is told and how. In this lab you will create an Action Group, build a metric alert on a VM's CPU, push the CPU above the threshold, and follow the alert from the raw metric to an email in someone's inbox.

  • Creating an Action Group with an email receiver
  • Creating a metric alert rule with a threshold, window and severity
  • Routing a second, lower-severity alert to a different Action Group
  • Triggering the alert with a CPU stress test
  • Checking fired alerts with the Alerts Management API

Why This Matters in Production

An alert closes the gap between "the metric existed" and "someone was told in time to act". Imagine an on-call engineer at a company like Cloudflare paged at 2 AM because a production service has already failed, when a properly routed alert hours earlier would have given the team time to fix it before customers noticed. The rule detects the problem, and the Action Group makes sure a human actually hears about it.

Core Principles

The alert rule evaluates a signal on a schedule, and when its condition is met it fires an alert and calls every Action Group attached to it. An Action Group can send email, SMS, voice calls and push notifications, call a webhook, or start automation such as a Logic App or Azure Function. A rule with no Action Group still records an alert in the portal, but nobody is notified.

flowchart TD M([VM metric
Percentage CPU]):::src --> R[Alert rule
avg above 85 for 5m]:::tool R -->|condition met| A[Fired alert]:::warn A --> G[Action Group]:::tool G --> E[Email on-call]:::ok G --> W[Webhook to pager]:::ok classDef src fill:#DBEAFE,color:#1E293B classDef tool fill:#326CE5,color:#FFFFFF classDef warn fill:#F97316,color:#FFFFFF classDef ok fill:#10B981,color:#FFFFFF

Azure Monitor has three common alert types. Metric alerts watch numeric platform metrics such as CPU. Log search alerts run a KQL query on a schedule. Activity log alerts react to control-plane events such as a VM being deleted. This lab uses a metric alert.

Detailed Step-by-Step Practical Lab

  1. Create a resource group and a test VM to monitor:
Bash
az group create --name rg-monitor-lab-central --location centralindia
az vm create \
--resource-group rg-monitor-lab-central \
--name vm-monitor-lab \
--image Ubuntu2204 \
--size Standard_B1s \
--admin-username azureadmin \
--generate-ssh-keys
  1. Create an Action Group with an email receiver for the on-call engineer. Azure sends that address a notification that it was added to the group:
Bash
az monitor action-group create \
--resource-group rg-monitor-lab-central \
--name ag-oncall-team \
--short-name oncall \
--action email oncall-engineer rahul@devops.in
  1. Create a metric alert on CPU, attached to that Action Group. The rule evaluates every minute over a 5-minute window, and severity 2 marks it as a warning that needs attention:
Bash
VM_ID=$(az vm show \
--resource-group rg-monitor-lab-central \
--name vm-monitor-lab \
--query "id" --output tsv)
az monitor metrics alert create \
--name "high-cpu-alert-lab" \
--resource-group rg-monitor-lab-central \
--scopes "$VM_ID" \
--condition "avg Percentage CPU > 85" \
--window-size 5m \
--evaluation-frequency 1m \
--severity 2 \
--description "VM CPU above 85 percent for 5 minutes" \
--action ag-oncall-team
  1. Add a second Action Group and a lower-severity rule so early warnings go to the team instead of the on-call phone:
Bash
az monitor action-group create \
--resource-group rg-monitor-lab-central \
--name ag-team-warnings \
--short-name warnings \
--action email platform-team team-platform@devops.in
az monitor metrics alert create \
--name "warn-cpu-alert-lab" \
--resource-group rg-monitor-lab-central \
--scopes "$VM_ID" \
--condition "avg Percentage CPU > 70" \
--window-size 5m \
--evaluation-frequency 1m \
--severity 3 \
--action ag-team-warnings
  1. Confirm both rules exist and are enabled:
Bash
az monitor metrics alert list \
--resource-group rg-monitor-lab-central \
--query "[].[name,severity,enabled]" --output table
  1. Push the VM's CPU above the threshold. The systemd-run command keeps the stress test running after the command returns:
Bash
az vm run-command invoke \
--resource-group rg-monitor-lab-central \
--name vm-monitor-lab \
--command-id RunShellScript \
--scripts "sudo apt-get update && sudo apt-get install -y stress-ng && sudo systemd-run --unit=cpu-stress stress-ng --cpu 2 --timeout 900s"
  1. Wait about 6 to 10 minutes. The rule needs a full window of high CPU, and metric data and email delivery add a few minutes. Then check the inbox of the address in the Action Group, and list the fired alerts. The rule also sends a notification when CPU drops again, because auto-resolve is on by default:
Bash
SUB_ID=$(az account show --query id --output tsv)
az rest --method get \
--uri "https://management.azure.com/subscriptions/$SUB_ID/providers/Microsoft.AlertsManagement/alerts?api-version=2019-05-05-preview" \
--query "value[].[properties.essentials.alertRule,properties.essentials.severity,properties.essentials.monitorCondition]" \
--output table

You can also open Monitor -> Alerts in the portal to see the same alert instances with their severity and state.

  1. Clean up. Deleting the group removes the VM, both rules and both Action Groups:
Bash
az group delete --name rg-monitor-lab-central --yes --no-wait

Production Best Practices & Common Pitfalls

Common Mistake

Creating an alert rule but forgetting to attach an Action Group, or attaching one with an address nobody reads. The alert still appears in Azure's alert history, but if nobody is notified promptly it protects nothing.

Tip

Alert on signals that predict a problem, not only ones that confirm it. A disk filling up leaves time to act, while an "application crashed" alert means the outage has already started.

Remember

Platform metrics do not include free disk space or memory inside the guest OS. Alerts on those need guest metrics collected by the Azure Monitor Agent, so set up collection before you rely on them.

  • Choose the window and frequency carefully. A window that is too short fires on harmless spikes, and one that is too long delays a real alert past the point where it helps.
  • Route severities to different Action Groups. A critical outage should reach an on-call phone, while a low-priority warning goes to a shared channel. Treating every alert the same buries the ones that need action now.
  • Send to a paging tool, not just email. For real on-call, add a webhook receiver to PagerDuty or Opsgenie, since email can sit unread overnight.
  • Mind the rate limits. Action Groups limit how many emails and SMS messages they send per address in a period, so a noisy rule can silence itself and hide a real incident.
  • Use alert processing rules for maintenance. They suppress notifications during planned work without deleting your alert rules.
  • Scale rules with multiple scopes. One metric alert can watch many resources of the same type in a region, which beats creating a rule per VM.
  • Prefer dynamic thresholds for variable load. They learn normal patterns and flag deviations, which suits metrics with daily peaks better than a fixed number.

Quick Reference & Troubleshooting Commands

Command Description
az monitor action-group create Create a new Action Group
az monitor metrics alert create Create a metric-based alert rule
az monitor metrics alert list List alert rules with severity and state
az monitor metrics alert show Check one alert rule's configuration
az rest --uri ".../Microsoft.AlertsManagement/alerts" List fired alert instances

Explore More in Azure Monitoring, Identity, and Production Readiness

All 6 Topics

Frequently Asked Questions

Is Building Azure Monitor Alerts and Action Groups free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Building Azure Monitor Alerts and Action Groups topic cover?

Learn to configure Azure Monitor alert rules and Action Groups so the right people are notified before a problem becomes an outage.

Found a mistake, an outdated step or a broken link?