CloudWatch metrics, logs and alarms
Start with a slow bookstore
A monitoring system collects observations about a workload. Observability means using those observations to reason about what is happening inside it. Amazon CloudWatch collects and displays metrics, logs and other telemetry. Imagine a bookstore whose checkout suddenly becomes slow. A latency graph shows when the slowdown began, a log entry describes a failed operation, and a trace follows one request across components. These are complementary signals, not interchangeable records. All values below are invented.
Metric: latency = 900 msLog: request=r-17 level=ERROR component=checkoutTrace: browser -> checkout -> inventoryMetrics, dimensions and statistics
A metric is a time series of numeric observations. A namespace groups related metrics; dimensions are name/value pairs that identify a series. For example, EC2 CPUUtilization for one InstanceId differs from the series for another instance. Check namespace, dimensions, region, unit, period and statistic before comparing graphs. Average answers a different question from Maximum or Sum. A percentile such as p95 summarizes the distribution, not the percentage of errors. If 8 out of 200 requests fail, the error rate is 4%. If there are no requests, the ratio is undefined; do not silently report zero. A dashboard puts selected graphs together but is not a complete inventory or proof of health.
errors = 8requests = 200error rate = 8 / 200 * 100 = 4%Metric alarms and missing observations
A metric alarm evaluates a chosen statistic against a threshold over configured periods. For a beginner example use two breaching one-minute periods out of the last three, with a threshold strictly greater than 500 ms. The series 420, 650, 700 breaches in two periods. The main states are OK, ALARM and INSUFFICIENT_DATA. Missing observations are not zero; CloudWatch supports missing-data treatments including breaching, notBreaching, ignore and missing. Actual evaluation can retrieve older points and has special cases, so the three-value rule here is only a simplified worksheet. An alarm can trigger a configured action, such as a notification, but cannot by itself diagnose or guarantee repair.
period_ms_values = [420, 650, 700]threshold_ms = 500breaches = 2 of 3Logs, traces and retention
CloudWatch Logs organizes events in log streams and log groups. A group can have a retention policy; application logs must first be collected or delivered. Logs Insights can query collected logs. Use structured records with time, component, severity and a synthetic request ID to correlate errors. A distributed trace represents a request as spans for operations; sampling may omit requests, and identifiers must be propagated to connect components. Do not write secrets, payment details or raw customer bodies to logs. Ingestion, stored data, queries, custom metrics and alarms can all affect cost. As a hypothetical example 2 GB/day for 10 days is 20 GB ingested; a shorter retention period does not undo ingestion. Check current rates and choose retention according to operational and compliance needs.
Practice: choose evidence
A checkout graph rises while CPU stays low. Find slow request IDs in synthetic logs and compare the spans before concluding which dependency is slow. Check the time zone, selected dimensions and missing points. Do not restart the instance simply because a graph changed. Explain why an audit event and a billing report cannot replace application latency data. Next, learn how to establish a timeline of configuration changes with CloudTrail and Config.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
CloudWatch metrics, logs and alarms — knowledge check
Apply monitoring and incident reasoning to the fictional bookstore.
Which signal follows one request across services?
Eight of 200 requests fail. What is the error rate?
The last three latency samples are 420, 650 and 700 ms. Two must exceed 500 ms. What does the worksheet report?
A metric stops arriving. What should you do first?
What does reducing log retention not undo?