CloudWatch metrics and alarms
Namespaces, dimensions, statistics and retention, custom metrics, and alarms: M-of-N evaluation, missing data, composite alarms and actions.
Launching and connecting to instancesSNS topics and fan-outLaunch templates and Auto Scaling groups
CloudWatch metrics and alarms
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A metric is identified by its namespace, name and exact set of dimensions. Every new combination is a separate, billable metric.
- Averages hide slow requests. Alarm on percentiles for latency and on error ratios, not raw counts.
- EC2 publishes hypervisor-level metrics. Memory and disk space need the CloudWatch agent or another collector.
- Fine detail ages out: one-minute data points are kept 15 days, five-minute 63 days and one-hour 15 months.
- Decide how each alarm treats missing data, and require M of N breaching points to avoid flapping.
- Alarm on what users feel, send it somewhere a person or automation will act, and combine noisy alarms into composite ones.
You can’t log in and look
With one server you could watch top. With functions, containers and managed databases there is often nothing to log in to, and nobody watching at night anyway. You need numbers collected continuously, and something that speaks up when they go wrong. On AWS the default place for both is Amazon CloudWatch. The general discipline is in monitoring and alerting.
What a metric is
A metric is a time series identified by three things: a namespace (AWS/SQS, or your own Shop), a name, and up to 30 dimensions, which are name and value pairs such as Service=checkout. Most AWS services publish their own for free.
The identity rule trips people up. For your own metrics, each combination of dimensions is a separate metric, and CloudWatch does not add them up for you. Think of them as separately labelled drawers, not a database you can query by any column.
I published ten latency values with Service=checkout,Stage=prod to moto, a local emulator: nine of 40 ms and one of 2000 ms. moto returned the same statistics whether I asked with both dimensions, one or none. Real CloudWatch would not: AWS documents that it doesn’t aggregate custom metrics across dimensions, so the last two queries would find nothing. Don’t learn this behaviour from an emulator.
The statistics are still instructive:
SampleCount 10 Average 236 Maximum 2000
The average describes no request at all. Nine were six times faster than it and one was eight times slower. For latency use percentiles (p99, p95); for failures use errors divided by requests, which metric math can compute in the alarm.
Sources, resolution, retention
EC2’s built-in metrics cover what is visible from outside the machine, such as CPU and network. By default they arrive every 5 minutes (status checks every minute); detailed monitoring gives 1 minute. Memory and filesystem usage live inside the guest, so they need the CloudWatch agent or another collector.
For your own metrics you can call PutMetricData, write embedded metric format log lines that CloudWatch turns into metrics, or send OpenTelemetry metrics, which AWS now recommends for new work.
Detail is not kept forever. Sub-minute points last 3 hours, 1-minute 15 days, 5-minute 63 days and 1-hour 455 days. Investigating last quarter, you will only have hourly data.
Alarms
An alarm is OK, ALARM or INSUFFICIENT_DATA, and acts when it changes state (Auto Scaling actions repeat while it stays there).
aws cloudwatch put-metric-alarm --alarm-name checkout-slow \
--namespace Shop --metric-name CheckoutLatency \
--dimensions Name=Service,Value=checkout Name=Stage,Value=prod \
--extended-statistic p99 --period 60 \
--evaluation-periods 5 --datapoints-to-alarm 3 \
--threshold 500 --comparison-operator GreaterThanThreshold \
--treat-missing-data notBreaching
Read it as: p99 over each minute; alarm if 3 of the last 5 minutes exceed 500 ms. That M out of N shape ignores one bad minute and still catches an intermittent problem.
Missing data needs a decision: breaching, notBreaching, ignore (keep the current state) or missing, the default.
Other kinds: anomaly detection alarms compare against a learned band; composite alarms combine other alarms with a rule, so one page replaces six; PromQL alarms work on OpenTelemetry metrics.
Actions include notifying an SNS topic, scaling a group, recovering an instance and starting automation. Test the path with set-alarm-state; an alarm nobody receives is decoration.
What to alarm on
Start with symptoms: error rate, latency, and the age of the oldest queued message. Then known cliffs: disk full, connection limits, a dead-letter queue that isn’t empty. CPU at 90 percent alone is often just a busy, healthy machine. More on that in alerting on symptoms.
Dashboards and cost
A dashboard is for the person who has already been woken: put the symptom graphs first, then the dependencies that could explain them, with deployment times marked if you can. Remember that custom metrics, detailed monitoring and high-resolution alarms are billed, so a dimension added casually is a line on the bill as well as a new drawer to look in.
About the video
The embed is a clip (0:40 to 31:18) of DheerajTechInsight’s CloudWatch tutorial, November 2025. Its chapters in that range cover what CloudWatch is, metrics, a metrics preview, alarms and a demo creating one. The dashboard demo and best practices follow on YouTube. I judged it from chapters and description only, since transcripts couldn’t be fetched. English was judged from the “English (US) original” audio track. An 11-minute metrics basics video is in deeper.
What was run: the published values, statistics and alarm creation ran on moto 5.1.22, which says nothing about how AWS evaluates an alarm and, as above, wrongly aggregates dimensions. Everything else is from the AWS docs, checked 2026-11-29.
Where this fits
Metrics say that something is wrong. To find out what, you read logs.
Check yourself
You publish a latency metric with dimensions Service and Stage. An alarm that specifies only Service stays in INSUFFICIENT_DATA. Why?
For custom metrics CloudWatch does not aggregate across dimensions. A metric with only the Service dimension was never published. Specify both, or publish the aggregate too.
An error-count metric is only published when an error happens. How should the alarm treat missing data?
As notBreaching, because no data means no errors. For a heartbeat metric it is the reverse: silence is the failure, so treat missing data as breaching.
What does an alarm with 5 evaluation periods and 3 datapoints to alarm do that 3 of 3 does not?
It tolerates gaps. Any 3 breaching points within the last 5 trigger it, consecutive or not, so a problem that comes and goes is still caught while a single spike is ignored.
Why might putting a request ID in a metric dimension be an expensive mistake?
Each distinct value creates a new metric, so you get millions of metrics with one data point each. Put high-cardinality identifiers in logs or traces.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.