CloudWatch Metrics, Alarms and Dashboards
Overview
Amazon CloudWatch is the monitoring service of AWS. Every service publishes metrics (time-ordered data points such as CPU utilisation), and CloudWatch lets you graph them on dashboards, evaluate them with alarms and trigger actions when thresholds are crossed.
Think of the dashboard of a car. Speed, fuel and temperature are metrics; the warning light is an alarm. A good operator does not stare at the gauges all day – they configure lights that tell them when something needs attention.
For SysOps the key skill is knowing what is monitored by default and what is not. EC2 reports CPU, network and disk I/O (of instance store) out of the box, but memory, disk space and processes require the CloudWatch agent. That distinction appears in almost every SOA-C03 monitoring scenario.
Key Concepts
- A metric is identified by namespace + metric name + dimensions (e.g. AWS/EC2, CPUUtilization, InstanceId).
- EC2 basic monitoring is 5-minute; detailed monitoring is 1-minute (extra cost). Custom metrics can be standard (1 min) or high-resolution (1 s).
- Memory, swap, disk-space and per-process metrics are NOT default – install the CloudWatch agent (collects metrics and logs).
- Alarm states: OK, ALARM, INSUFFICIENT_DATA; configure treat missing data as missing, notBreaching, breaching or ignore.
- Alarm actions: SNS notification, EC2 actions (stop/terminate/reboot/recover), Auto Scaling policy, Systems Manager OpsItem/incident.
- Composite alarms combine alarms with AND/OR/NOT logic to cut alert noise.
- Anomaly detection builds an ML band around expected values instead of a static threshold.
- Metric data retention: 1 s data for 3 hours, 1 min for 15 days, 5 min for 63 days, 1 hour for 455 days (15 months).
Detailed Notes
Metric anatomy
| Part | Example | Notes |
|---|---|---|
| Namespace | AWS/EC2, CWAgent | Container for metrics; custom namespaces cannot start with AWS/ |
| Metric name | CPUUtilization | |
| Dimensions | InstanceId=i-0abc | Up to 30; each unique combination is a separate metric |
| Period | 60 s, 300 s | Aggregation window for alarms and graphs |
| Statistic | Average, Sum, Max, p99 | Percentiles available for many metrics |
What EC2 gives you by default
| Available by default | Needs the CloudWatch agent |
|---|---|
| CPUUtilization, NetworkIn/Out | Memory used %, swap |
| DiskReadOps (instance store only) | Disk space used % (EBS file systems) |
| StatusCheckFailed (system / instance) | Process counts, netstat, custom app metrics |
| CPUCreditBalance (burstable) | Logs from files (/var/log/messages) |
Installing and configuring the agent
# Install via Systems Manager (instance needs an IAM role with CloudWatchAgentServerPolicy)
aws ssm send-command --document-name AWS-ConfigureAWSPackage \
--targets Key=tag:Env,Values=prod \
--parameters action=Install,name=AmazonCloudWatchAgent
# Store the agent config in Parameter Store and start the agent from it
aws ssm send-command --document-name AmazonCloudWatch-ManageAgent \
--targets Key=tag:Env,Values=prod \
--parameters action=configure,mode=ec2,optionalConfigurationSource=ssm,optionalConfigurationLocation=AmazonCloudWatch-linux,optionalRestart=yes
A minimal agent configuration:
{
"metrics": {
"append_dimensions": { "AutoScalingGroupName": "${aws:AutoScalingGroupName}" },
"metrics_collected": {
"mem": { "measurement": ["mem_used_percent"] },
"disk": { "measurement": ["used_percent"], "resources": ["/"] }
}
},
"logs": { "logs_collected": { "files": { "collect_list": [
{ "file_path": "/var/log/messages", "log_group_name": "/prod/messages" } ] } } }
}
Creating an alarm
aws cloudwatch put-metric-alarm --alarm-name web-high-cpu \
--namespace AWS/EC2 --metric-name CPUUtilization \
--dimensions Name=AutoScalingGroupName,Value=web-asg \
--statistic Average --period 300 --evaluation-periods 3 --datapoints-to-alarm 3 \
--threshold 80 --comparison-operator GreaterThanThreshold \
--treat-missing-data notBreaching \
--alarm-actions arn:aws:sns:us-east-1:111122223333:ops-alerts
evaluation-periods and datapoints-to-alarm give "M out of N" logic and prevent flapping.
EC2 auto-recovery
Alarm on StatusCheckFailed_System with action arn:aws:automate:us-east-1:ec2:recover to move the instance to new hardware (same instance ID, IP and EBS volumes). Use StatusCheckFailed_Instance with the reboot action for OS-level hangs. Many modern instance types also use simplified automatic recovery by default.
Custom and high-resolution metrics
aws cloudwatch put-metric-data --namespace MyApp --metric-name QueueLatencyMs \
--value 120 --unit Milliseconds --storage-resolution 1
Dashboards, Metric Math and composite alarms
- Dashboards are global, can combine metrics from multiple Regions and accounts (cross-account observability via OAM), and can be shared.
- Metric math computes expressions, e.g. error rate =
100 * errors / requests. - Composite alarm:
ALARM("HighCpu") AND ALARM("HighLatency")pages only when both fire. - Metric Streams push metrics near real time to Kinesis Data Firehose (S3, Datadog, etc.).
Alarm gotchas
| Symptom | Likely cause |
|---|---|
| Alarm stuck in INSUFFICIENT_DATA | Metric not being published; wrong dimensions; agent stopped |
| Alarm flaps constantly | Evaluation period too short; use M-of-N |
| No email received | SNS subscription not confirmed or topic policy blocks CloudWatch |
A composite alarm combines other alarms with AND, OR and NOT so that on-call is paged only when several symptoms agree (for example high latency AND high error rate) and noisy child alarms stay silent. Composite alarms can invoke only SNS, Systems Manager (OpsItems and incidents) and Lambda through SNS, not EC2 or Auto Scaling actions, which are reserved for metric alarms.
aws cloudwatch put-composite-alarm --alarm-name checkout-degraded \
--alarm-rule "ALARM(api-p99-latency) AND ALARM(api-5xx-rate)" \
--alarm-actions arn:aws:sns:us-east-1:111122223333:ops-alerts \
--actions-suppressor maintenance-window-alarm --actions-suppressor-wait-period 120
aws cloudwatch put-anomaly-detector --namespace AWS/ApplicationELB --metric-name RequestCount \
--stat Sum --dimensions Name=LoadBalancer,Value=app/web/abc
| Capability | Use it for | Notes |
|---|---|---|
| Anomaly detection band | Metrics with daily/weekly seasonality | Alarm on LessThanLowerOrGreaterThanUpperThreshold |
| Metric math | Error rate = errors / requests x 100 | Alarm directly on the expression |
| Alarm actions | SNS, EC2 stop/terminate/reboot/recover, ASG policy, SSM OpsItem | Action is taken when state changes to the configured state |
| Cross-account / cross-Region dashboards | One view across an organization | Enable cross-account observability with Organizations sink and links |
| Dashboard sharing | Give read access without IAM users | Share by account, public link or SSO |
Services publish to SNS in two ways: alarm actions (CloudWatch calls SNS) and service notifications (for example S3 events, Auto Scaling notifications, AWS Backup and CloudFormation --notification-arns). In both cases the SNS topic access policy must allow the publishing service principal, and email subscriptions must be confirmed. Cross-account dashboards need the monitoring account to be linked to source accounts through CloudWatch cross-account observability.
Real World Example
Scenario – memory leaks on a Java fleet. A team notices instances become sluggish every few days, yet the CPU graph looks healthy. They realise EC2 does not report memory. They deploy the CloudWatch agent through an SSM State Manager association, collecting mem_used_percent and disk usage with the ASG name as a dimension.
They add an alarm: memory above 85% for 3 of 5 minutes, which notifies an SNS topic and invokes an SSM Automation document that drains and replaces the instance. A composite alarm combines high memory with high latency so on-call only gets paged when users are affected. A dashboard shows both metrics beside ALB 5xx counts.
Architecture Diagram
The agent publishes OS metrics; alarms evaluate them and trigger actions.
- 1The CloudWatch agent on each instance reads memory and disk statistics.
- 2It publishes them as custom metrics in the CWAgent namespace.
- 3An alarm evaluates the metric over a period, using M-of-N datapoints.
- 4On ALARM the alarm notifies SNS and triggers a scaling or recovery action.
Best Practices
- ✓Deploy the CloudWatch agent with SSM and keep its config in Parameter Store so every instance uses the same settings.
- ✓Alarm on symptoms users feel (latency, 5xx, queue age) as well as resource saturation.
- ✓Use M-of-N datapoints and the correct treat-missing-data setting to avoid flapping and silent failures.
- ✓Use composite alarms to reduce alert fatigue and route severity-based notifications.
- ✓Tag resources and build per-service dashboards; use cross-account observability for central operations.
Common Interview Questions
Exam Tips
SOA-C03 focus
- Memory, swap or disk-space metrics -> CloudWatch agent. CPU, network, status checks -> default.
- 1-minute EC2 metrics -> detailed monitoring. Sub-minute custom metrics -> high-resolution (storage-resolution 1).
- Alarm in INSUFFICIENT_DATA -> check metric is published, dimensions match, and treat missing data setting.
- Automatically recover a failed instance -> alarm on StatusCheckFailed_System + recover action.
Finished this lesson?
0 of 46 lessons done · 0% of the course

