CloudWatch metrics, alarms and dashboards
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Operations and security
-
Phase 3: SQL Server on AWS
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
Graphs that nobody looks at don’t help anyone. CloudWatch alarms are what turn those metrics into action, so when CPU stays high, memory runs out or a server fails its checks, the right person gets an email or a page before customers start calling.
You’ll set up the saat-alerts topic that the rest of the course uses, install the CloudWatch agent so you get memory metrics, and build a CPU alarm that you then prove with real load. After that you’ll put the key numbers on one dashboard and fix two alarm mistakes that make on-call engineers miss real incidents.
| Time | You need | By the end you can |
|---|---|---|
| 75 minutes (one small instance and four interface endpoints for about an hour) | saat-vpc, Start-SsmEndpoints.ps1 and Stop-SsmEndpoints.ps1, saat-ec2-ssm-profile, an email address you can open, your laptop signed in as saat-admin. Cost: about USD 0.20 (endpoints, detailed monitoring and a few custom metrics for an hour). | Set up SNS email alerts, collect memory metrics with the CloudWatch agent, write alarms with sensible M of N and missing-data settings, test them without breaking anything, and build a dashboard. |
What it is, in one line
CloudWatch alarms watch a metric and move between states (OK, ALARM, INSUFFICIENT_DATA) when it crosses a threshold, and on that change they can do something, like send an SNS notification.
In Simple Words
The pressure cooker whistle
Nobody stands and stares at a pressure cooker for twenty minutes; you get on with other work and wait for the whistle, and a CloudWatch alarm is that whistle for your servers. A good whistle doesn’t go off for every puff of steam, only when the pressure stays high, which is what “two out of three minutes above 40 percent” means. But if the whistle itself is blocked you hear nothing at all, and that’s INSUFFICIENT_DATA: the alarm has no numbers to judge, so it stays quiet at the moment you need it most.
Engineer's View
How CloudWatch metrics and alarms really work
A metric is a time series, and it’s identified by its namespace, its name and its dimensions. AWS/EC2 CPUUtilization InstanceId=i-... is one metric, and if you add another dimension to the same name you’ve got a different metric. EC2 sends basic metrics every 5 minutes, or every minute if you turn on detailed monitoring. Memory and disk usage live inside the OS where EC2 can’t see them, so the CloudWatch agent publishes them to the CWAgent namespace.
An alarm looks at a statistic over a period, and with “datapoints to alarm” (M out of N evaluation periods) it can ignore short spikes. You can tell it to treat missing data as missing, notBreaching, breaching or ignored. Alarms only act when the state changes, and the action can notify SNS, scale an Auto Scaling group, or stop, reboot or recover an EC2 instance, as long as it’s in the same Region as the alarm.
To test the notification path, use set-alarm-state; the alarm goes back to its real state at the next evaluation. For less noise you can use composite alarms, which combine several alarms, and metric math alarms let you watch a calculated value such as error rate.
How it works, step by step
This is how a busy CPU ends up as an email in your inbox.
1The instance reports a number
With detailed monitoring on, EC2 publishes CPUUtilization for mon01 every minute, and the agent adds mem_used_percent from inside Linux.
2The alarm evaluates it
Every minute the alarm looks at the last three datapoints. If two of them are above 40 percent it goes to ALARM, otherwise it stays OK.
3A state change triggers actions
Going from OK to ALARM publishes to saat-alerts, and so does going back from ALARM to OK, so whoever is on call also hears when it’s over.
4Every setting matters
Read any alarm definition in this order:
When an alarm is noisy, the threshold is usually too low or M of N is set to 1 of 1. When an alarm stays silent, it’s usually watching the wrong dimensions or treating missing data as notBreaching.
✅ Checkpoint: You can explain what makes two metrics different, why memory needs the agent, what M of N does, and why INSUFFICIENT_DATA is dangerous.
Hands-on lab: CloudWatch alarms that reach a person
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.
Start the lab the usual way and then set your email address:
cd C:\aws-lab
aws login --profile saat-admin
$env:AWS_PROFILE = 'saat-admin'
$env:Path += ';C:\Program Files\Amazon\SessionManagerPlugin\bin'
$v = Get-Content C:\aws-lab\saat-vpc.json | ConvertFrom-Json
$email = 'you@example.com'
.\Start-SsmEndpoints.ps11Create the alert topic and confirm your email
Paste the whole block and then go to your inbox:
$topic = aws sns create-topic --name saat-alerts --tags Key=course,Value=saatvedha-aws --query TopicArn --output text
aws sns subscribe --topic-arn $topic --protocol email --notification-endpoint $email --query SubscriptionArn --output textYou should see this:
pending confirmationClick Confirm subscription in the email from AWS Notifications. If you skip this, every alarm will look like it “works” and you’ll get nothing. Check it:
aws sns list-subscriptions-by-topic --topic-arn $topic --query "Subscriptions[0].SubscriptionArn" --output textOnce you’ve confirmed, it should look something like this:
arn:aws:sns:ap-south-1:111122223333:saat-alerts:6f1c2d3e-4a5b-6c7d-8e9f-0a1b2c3d4e5fDon’t delete saat-alerts, because Budgets, GuardDuty and backups will send to it in later lessons.
2Prepare the CloudWatch agent
Paste the whole block. It gives the role permission to publish metrics, stores the agent config and adds a monitoring endpoint:
aws iam attach-role-policy --role-name saat-ec2-ssm-role --policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
@'
{
"agent": { "metrics_collection_interval": 60 },
"metrics": {
"namespace": "CWAgent",
"append_dimensions": { "InstanceId": "${aws:InstanceId}", "InstanceType": "${aws:InstanceType}" },
"metrics_collected": {
"mem": { "measurement": [ "mem_used_percent" ] }
}
}
}
'@ | Set-Content cwagent.json
aws ssm put-parameter --name AmazonCloudWatch-saat-linux --type String --value file://cwagent.json --overwrite | Out-Null
$mon = aws ec2 create-vpc-endpoint --vpc-id $v.VpcId --vpc-endpoint-type Interface --service-name com.amazonaws.ap-south-1.monitoring --subnet-ids $v.PrivateA --security-group-ids $v.EndpointSg --private-dns-enabled --tag-specifications 'ResourceType=vpc-endpoint,Tags=[{Key=Name,Value=saat-monitoring-ep},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=23}]' --query VpcEndpoint.VpcEndpointId --output text
do { Start-Sleep 15; $s = aws ec2 describe-vpc-endpoints --vpc-endpoint-ids $mon --query "VpcEndpoints[0].State" --output text } until ($s -eq 'available')
$sYou should see this:
availablePrivate servers have no internet access, so the agent talks to CloudWatch through this endpoint. The policy and the parameter stay for Lesson 24, but the endpoint gets deleted at the end.
3Launch mon01 and build the CPU alarm
Paste the whole block:
[IO.File]::WriteAllText('C:\aws-lab\mon-userdata.sh', "#!/bin/bash`ndnf install -y amazon-cloudwatch-agent`n/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c ssm:AmazonCloudWatch-saat-linux`n")
$base = aws ssm get-parameter --name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 --query Parameter.Value --output text
$i = aws ec2 run-instances --image-id $base --instance-type t3.micro --subnet-id $v.PrivateA --security-group-ids $v.AppSg --iam-instance-profile Name=saat-ec2-ssm-profile --metadata-options HttpTokens=required --monitoring Enabled=true --user-data file://mon-userdata.sh --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=mon01},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=23}]' --query "Instances[0].InstanceId" --output text
aws cloudwatch put-metric-alarm --alarm-name saat-mon01-cpu-high --alarm-description "mon01 CPU above 40% for 2 of 3 minutes" --namespace AWS/EC2 --metric-name CPUUtilization --dimensions "Name=InstanceId,Value=$i" --statistic Average --period 60 --evaluation-periods 3 --datapoints-to-alarm 2 --threshold 40 --comparison-operator GreaterThanThreshold --treat-missing-data missing --alarm-actions $topic --ok-actions $topic
aws cloudwatch set-alarm-state --alarm-name saat-mon01-cpu-high --state-value ALARM --state-reason "Testing the alert path"
aws cloudwatch describe-alarms --alarm-names saat-mon01-cpu-high --query "MetricAlarms[0].[StateValue,StateReason]" --output textYou should see this, and an ALARM email should land within a minute:
ALARM Testing the alert pathTeams use set-alarm-state to check that alerts reach people without breaking anything. About a minute later the alarm looks at the real data again and sends an OK email.

4Cause real load, then build the dashboard
Paste the whole block. The load command keeps your prompt busy for five minutes:
do { Start-Sleep 20; $p = aws ssm describe-instance-information --filters "Key=InstanceIds,Values=$i" --query "InstanceInformationList[0].PingStatus" --output text } until ($p -eq 'Online')
aws ssm start-session --target $i --document-name AWS-StartInteractiveCommand --parameters command="timeout 300 yes > /dev/null"
Start-Sleep 90
aws cloudwatch describe-alarm-history --alarm-name saat-mon01-cpu-high --history-item-type StateUpdate --query "AlarmHistoryItems[].HistorySummary" --output text
$alarmArn = aws cloudwatch describe-alarms --alarm-names saat-mon01-cpu-high --query "MetricAlarms[0].AlarmArn" --output text
@'
{
"widgets": [
{ "type": "metric", "x": 0, "y": 0, "width": 12, "height": 6,
"properties": { "title": "mon01 CPU %", "region": "ap-south-1", "stat": "Average", "period": 60,
"metrics": [ [ "AWS/EC2", "CPUUtilization", "InstanceId", "INSTANCE_ID" ] ] } },
{ "type": "metric", "x": 12, "y": 0, "width": 12, "height": 6,
"properties": { "title": "mon01 memory %", "region": "ap-south-1", "stat": "Average", "period": 60,
"metrics": [ [ "CWAgent", "mem_used_percent", "InstanceId", "INSTANCE_ID", "InstanceType", "t3.micro" ] ] } },
{ "type": "alarm", "x": 0, "y": 6, "width": 24, "height": 3,
"properties": { "title": "Alarms", "alarms": [ "ALARM_ARN" ] } }
]
}
'@ -replace 'INSTANCE_ID', $i -replace 'ALARM_ARN', $alarmArn | Set-Content dash.json
aws cloudwatch put-dashboard --dashboard-name saat-ops --dashboard-body file://dash.jsonYou should see something like this, with the newest entry first:
Alarm updated from ALARM to OK Alarm updated from OK to ALARM Alarm updated from ALARM to OK Alarm updated from OK to ALARM Alarm updated from INSUFFICIENT_DATA to OK
{
"DashboardValidationMessages": []
}yes keeps one of the two vCPUs busy, so CPU sits near 50 percent and the alarm fires for real. You’ll get a second ALARM email and then an OK. Open CloudWatch, go to Dashboards and pick saat-ops, and you’ll see CPU, memory and the alarm on one screen.

✅ Checkpoint: saat-alerts has a confirmed email, the CPU alarm fired from set-alarm-state and from real load and went back to OK, and saat-ops shows CPU, memory and the alarm. Keep it all for the break lab.
Break It, Then Fix It
Here are two mistakes that keep alarms quiet while something is going wrong.
1Break it: a memory alarm with one dimension missing
Create a memory alarm that uses only InstanceId, wait four minutes and then check it:
aws cloudwatch put-metric-alarm --alarm-name saat-mon01-mem-high --namespace CWAgent --metric-name mem_used_percent --dimensions "Name=InstanceId,Value=$i" --statistic Average --period 60 --evaluation-periods 3 --threshold 80 --comparison-operator GreaterThanThreshold --alarm-actions $topic
Start-Sleep 240
aws cloudwatch describe-alarms --alarm-names saat-mon01-mem-high --query "MetricAlarms[0].[StateValue,StateReason]" --output textYou should see this:
INSUFFICIENT_DATA Insufficient Data: 3 datapoints were unknown.
The agent is sending memory data, but with two dimensions on it. There’s no metric with InstanceId alone, so the alarm sits waiting forever and would never wake anyone up. Fix: ask CloudWatch which dimensions the metric has and use every one of them:
aws cloudwatch list-metrics --namespace CWAgent --metric-name mem_used_percent --query "Metrics[0].Dimensions"
aws cloudwatch put-metric-alarm --alarm-name saat-mon01-mem-high --namespace CWAgent --metric-name mem_used_percent --dimensions "Name=InstanceId,Value=$i" Name=InstanceType,Value=t3.micro --statistic Average --period 60 --evaluation-periods 3 --threshold 80 --comparison-operator GreaterThanThreshold --alarm-actions $topic
Start-Sleep 180
aws cloudwatch describe-alarms --alarm-names saat-mon01-mem-high --query "MetricAlarms[0].StateValue" --output textYou should see something like this:
[
{
"Name": "InstanceId",
"Value": "i-0d1e2f3a4b5c60021"
},
{
"Name": "InstanceType",
"Value": "t3.micro"
}
]
OK2Break it: send alarms to a topic in another Region
Say a team copies an alarm script over from their N. Virginia account:
$wrongTopic = $topic -replace 'ap-south-1', 'us-east-1'
aws cloudwatch put-metric-alarm --alarm-name saat-mon01-status --namespace AWS/EC2 --metric-name StatusCheckFailed --dimensions "Name=InstanceId,Value=$i" --statistic Maximum --period 60 --evaluation-periods 2 --threshold 1 --comparison-operator GreaterThanOrEqualToThreshold --alarm-actions $wrongTopicYou’ll get this error back:
An error occurred (ValidationError) when calling the PutMetricAlarm operation: Invalid region us-east-1 specified. Only ap-south-1 is supported.An alarm and its SNS topic have to be in the same Region. Central teams forget this a lot and end up with alarms in five Regions and a topic in only one. Fix: create a topic in each Region you monitor, or forward the events with EventBridge.
Run it again with the Mumbai topic:
aws cloudwatch put-metric-alarm --alarm-name saat-mon01-status --namespace AWS/EC2 --metric-name StatusCheckFailed --dimensions "Name=InstanceId,Value=$i" --statistic Maximum --period 60 --evaluation-periods 2 --threshold 1 --comparison-operator GreaterThanOrEqualToThreshold --alarm-actions $topic
aws cloudwatch describe-alarms --alarm-name-prefix saat-mon01 --query "MetricAlarms[].AlarmName" --output textYou should see this:
saat-mon01-cpu-high saat-mon01-mem-high saat-mon01-statusNow clean up. saat-alerts, the agent parameter and the role policy stay because later lessons need them:
aws cloudwatch delete-alarms --alarm-names saat-mon01-cpu-high saat-mon01-mem-high saat-mon01-status
aws cloudwatch delete-dashboards --dashboard-names saat-ops
aws ec2 terminate-instances --instance-ids $i | Out-Null
aws ec2 delete-vpc-endpoints --vpc-endpoint-ids $mon | Out-Null
aws ec2 wait instance-terminated --instance-ids $i
.\Stop-SsmEndpoints.ps1
Remove-Item cwagent.json, mon-userdata.sh, dash.json
.\Find-LabResources.ps1✅ Checkpoint: You fixed an INSUFFICIENT_DATA alarm by matching every dimension, and you fixed an alarm action that pointed at another Region. The alarms, dashboard, mon01 and endpoints are gone, and saat-alerts is still there.
This happened at work
The disk alarm that never fired
This one was at a payroll company. Every database server had a disk alarm on disk_used_percent above 85 percent that would page the DBA, and it had been green for a year. Then one Friday the payroll runs failed, and when the DBAs logged in they found a data drive 100 percent full with no page anywhere. Digging into it, they saw the alarm had been built with two dimensions, InstanceId and path. After an agent upgrade the agent also started sending device and fstype, so the old metric quietly stopped getting data, and because the alarm treated missing data as notBreaching it showed a calm green OK instead of INSUFFICIENT_DATA. They freed space and reran payroll overnight. Since then the team treats missing data as breaching on critical alarms, gets a weekly report of alarms sitting in INSUFFICIENT_DATA, and builds alarms in code from list-metrics output so a dimension change shows up in review.
Common mistakes and troubleshooting
| Mistake | What happens | What to do |
|---|---|---|
| Missing a dimension | INSUFFICIENT_DATA forever; no alert | Copy every dimension from list-metrics |
| Treating missing data as notBreaching on critical alarms | A dead metric looks healthy | Use breaching or missing, and review INSUFFICIENT_DATA alarms |
| Email subscription never confirmed | Alarms fire, nobody is told | Confirm and test with set-alarm-state |
| 1 of 1 datapoints on a spiky metric | Alert fatigue; people start ignoring pages | Use M of N, such as 3 of 5 |
| Expecting memory and disk without the agent | No such metrics in AWS/EC2 | Install the CloudWatch agent |
| SNS topic in another Region | ValidationError: Invalid region | Use a topic in the alarm’s Region |
Interview questions
Click a question to open it. Each one is phrased the way an interviewer would ask it, and under it you’ll find why they ask it and one way you could answer in your own words.
Fresher level
1. Can you explain in simple words what a CloudWatch alarm is?
Why they ask this: It’s a check on monitoring basics, since alarms are how a team hears about problems before users do.
How you might answer: It’s a rule that watches one metric, or a metric expression, and changes state between OK, ALARM and INSUFFICIENT_DATA when the value crosses a threshold. When the state changes it can run actions, like sending an SNS notification.
2. A teammate asks why CloudWatch shows CPU for an EC2 instance but not memory. What would you tell them?
Why they ask this: They want to know you understand what AWS can and can’t see inside a server, because it’s one of the first gaps people run into with EC2 monitoring.
How you might answer: I’d explain that memory and disk usage live inside the guest operating system and the hypervisor can’t see them, so they need to install the CloudWatch agent to publish those metrics.
3. You create a new alarm, and it just sits in INSUFFICIENT_DATA. What does that mean?
Why they ask this: They’re checking you understand alarm states, because an alarm stuck here isn’t protecting anything.
How you might answer: It means the alarm doesn’t have enough datapoints to decide. Usually the metric doesn’t exist with the dimensions I picked, or the resource has stopped, or the period is shorter than how often the metric arrives, so I’d check the dimensions and the period first.
2–5 years experience
4. Your on-call team says they get so many alerts they’ve started ignoring them. How would you fix that without missing real incidents?
Why they ask this: This is about alert design. Too many alerts is as bad as too few, because people stop reacting to them.
How you might answer: First I’d use M out of N datapoints so a single spike doesn’t page anyone, and base the thresholds on user impact. I’d group related signals with composite alarms and split alerts into warning and paging levels. Then once a month we’d go through the alarms that fired without anyone doing anything, and either fix them or remove them.
5. How would you test that an alarm actually reaches the on-call person, without breaking anything?
Why they ask this: They’re looking for good operational habits, since an alarm that never reaches a person is no better than having no alarm.
How you might answer: I’d run aws cloudwatch set-alarm-state to push the alarm into ALARM and then check the message turns up in the pager or chat. At the next evaluation it goes back to its real state, so nothing breaks.
6. Besides sending an email, what else can a CloudWatch alarm do for you?
Why they ask this: They want to see you think about automation and not only notifications, because some problems can be fixed without waking anyone up.
How you might answer: It can notify SNS and run Auto Scaling policies, it can stop, terminate, reboot or recover EC2 instances, and it can create Systems Manager OpsItems or incidents. On top of that, EventBridge gets alarm state change events, so you can trigger almost anything else from there.
Senior level
7. You’re asked to design monitoring for 300 servers across 4 accounts. How would you keep it consistent?
Why they ask this: They want standards that hold up at scale, because alarms hand-made on each server don’t survive growth.
How you might answer: I’d keep one standard agent config in Parameter Store and define alarms as code for each role, like web or database, with consistent names and tags. Cross-account observability brings it all into one monitoring account. Each service would get composite alarms, each severity would go to one SNS topic or incident tool, and a regular report would list any alarms stuck in INSUFFICIENT_DATA.
8. After an outage, you find the alarm stayed green the whole time. How do you investigate?
Why they ask this: They’re looking for an honest post-incident review where the aim is to close the gap, not to blame someone.
How you might answer: I’d start with the alarm history and the metric graph for that window, and compare the alarm’s dimensions with list-metrics. Then I’d look at the missing data setting, the period against how often the metric is sent, and whether the threshold matched user impact. I’d also confirm the action and the subscription worked, and once I’d found the gap I’d fix it and add a test for it.
Quick quiz
Q1. Which namespace holds memory metrics from the CloudWatch agent by default?
- AWS/EC2
- CWAgent
- AWS/Logs
- System/Linux
Show answer
B — The agent publishes to CWAgent unless you change it.
Q2. What does “2 of 3” datapoints to alarm do?
- Fires on any single spike
- Needs 2 breaching periods out of the last 3
- Checks 2 metrics
- Sends 3 emails
Show answer
B — M of N filters out short spikes.
Q3. How do you safely test that alarm emails arrive?
- Stop the instance
- set-alarm-state to ALARM
- Delete the metric
- Raise the threshold
Show answer
B — It forces a state change and reverts at the next evaluation.
Q4. Why did the memory alarm show INSUFFICIENT_DATA?
- The agent was off
- A dimension was missing
- The threshold was too high
- SNS was unconfirmed
Show answer
B — A metric is identified by all its dimensions.
Q5. Where must an alarm’s SNS topic be?
- us-east-1
- The same Region as the alarm
- Any Region
- Another account
Show answer
B — Cross-Region alarm actions are refused.
Quick recap
- A metric is its namespace, name and every dimension, and if you miss one you’re looking at a different metric.
- You need the CloudWatch agent for memory and disk.
- Use M of N and pick the right way to treat missing data.
- Confirm your SNS subscriptions and test them with set-alarm-state.
- Keep alarm actions in the alarm’s Region, and use saat-alerts as your alert topic from here on.
Next lesson
Lesson 24: CloudWatch Logs and Logs Insights → Next you’ll ship system and app logs with the agent, set retention, and track down errors quickly with Logs Insights queries.
Further reading: CloudWatch alarms
Want to go deeper into CloudWatch alarms? Read Using Amazon CloudWatch alarms and Collect metrics, logs and traces with the CloudWatch agent. You can also see the full plan for this course on the AWS Cloud Administration course page.
