Understanding Amazon CloudWatch Metrics
Metrics are time-ordered numeric data points that describe how a system behaves: CPU utilisation, request count, latency, queue depth. Amazon CloudWatch collects metrics from AWS services automatically and accepts custom metrics from applications. This lesson explains namespaces, dimensions, statistics, periods, resolution and retention, how to publish custom metrics, metric math and Metrics Insights, and cross-account observability.
Learning outcomes
After completing this lesson, you will be able to:
- Describe namespaces, metric names, dimensions, statistics including percentiles, and periods.
- Explain standard and high resolution, metric retention, and basic and detailed monitoring.
- Compare publishing custom metrics with PutMetricData and with the embedded metric format.
- Explain metric math, Metrics Insights queries and cross-account observability.
Metric Concepts
Every metric belongs to a namespace, such as AWS/EC2, AWS/ApplicationELB or a custom namespace such as Orders/Checkout, and has a name, such as CPUUtilization. Dimensions are name-value pairs that identify a specific series, such as InstanceId=i-0abc or LoadBalancer=app/prod/123; each unique combination of namespace, name and dimensions is a separate metric. Data points are aggregated over a period using a statistic: Average, Sum, Minimum, Maximum, SampleCount, percentiles such as p99, and trimmed statistics.
Choosing the statistic matters. Averages hide outliers: an average latency of 120 ms can coexist with 5% of requests taking three seconds. Percentiles such as p90 and p99 describe what the slowest users experience and are the right statistics for latency objectives. Sum suits counts such as errors, and Maximum suits saturation measures such as queue age.
The following diagram compares the average with the 99th percentile of the same latency metric.

Resolution, Retention and Monitoring Levels
Standard-resolution metrics have one-minute granularity. High-resolution custom metrics can have one-second granularity, which, with alarms evaluated every 10 or 30 seconds, detects short spikes faster at a higher cost. CloudWatch retains data with decreasing granularity as it ages, as shown below; older detail is aggregated, not lost entirely, but cannot be retrieved at fine granularity.
| Data point period | Retained for |
|---|---|
| Under 60 seconds (high resolution) | 3 hours |
| 60 seconds | 15 days |
| 5 minutes | 63 days |
| 1 hour | 455 days (15 months) |
EC2 publishes metrics every five minutes by default (basic monitoring) and every minute with detailed monitoring, which is charged. Detailed monitoring makes Auto Scaling and alarms react faster. EC2's default metrics come from the hypervisor, so they include CPU, network and disk operations for instance store, and EBS metrics come from the volumes, but memory and file system usage are not available without an agent, which is the subject of the next lesson.
Metric retention
Publishing Custom Metrics
Applications publish business and technical metrics that AWS cannot see, such as orders placed, payment failures or cache hit ratio. There are two main methods.
PutMetricData
The API call publishes one or more data points or statistic sets with dimensions, unit and storage resolution. It is simple but adds network calls and throttling considerations to the application; batching values and using statistic sets reduce calls.
Embedded metric format (EMF)
The application writes structured JSON log events that contain both log fields and metric definitions to CloudWatch Logs, for example through standard output in Lambda or the CloudWatch agent. CloudWatch extracts metrics from the logs asynchronously. EMF avoids synchronous API calls, keeps high-cardinality detail such as request IDs in the log record for investigation while publishing only aggregated metrics, and is supported by client libraries and Powertools for AWS Lambda. It is the recommended way to publish metrics from Lambda functions and containers.
{"_aws": {"Timestamp": 1767225600000,
"CloudWatchMetrics": [{"Namespace": "Orders/Checkout",
"Dimensions": [["Service", "PaymentMethod"]],
"Metrics": [{"Name": "CheckoutLatency", "Unit": "Milliseconds"},
{"Name": "CheckoutFailed", "Unit": "Count"}]}]},
"Service": "checkout", "PaymentMethod": "card",
"CheckoutLatency": 182, "CheckoutFailed": 0,
"requestId": "6c1f2b90-0d2e-4a7d-9a4f-2f0b8c3e9b11"}Each unique dimension combination is a separate billed metric, so dimensions should have bounded cardinality: a dimension such as customer ID or request ID would create millions of metrics. Such detail belongs in log fields, where Logs Insights or Contributor Insights can analyse it.
Publish the right metrics
Metric Math, Metrics Insights and Cross-Account Observability
Metric math combines metrics with expressions, for example computing an error rate as 100 * errors / requests, summing a metric across instances, filling gaps or using functions such as RATE, ANOMALY_DETECTION_BAND and SERVICE_QUOTA. Alarms and dashboards can use metric math results directly, so derived values do not need to be published.
Metrics Insights queries metrics with a SQL-like language, for example to find the ten instances with the highest CPU across a fleet, and can drive alarms on query results, which scale to fleets whose members change constantly. CloudWatch cross-account observability links source accounts to a monitoring account through Observability Access Manager sinks and links, so the monitoring account can view and alarm on metrics, logs, traces and Application Signals data from many accounts without switching accounts; it can be configured for a whole organisation.
Measuring What Matters
A checkout team monitors average CPU of its instances. Customers report slow checkouts that the dashboards do not show, and finance wants to see failed payments per payment method.
-
Latency
Use the ALB TargetResponseTime metric at p99, not the average, and alarm on it.
-
Business metrics
Publish CheckoutLatency and CheckoutFailed with EMF, with dimensions Service and PaymentMethod (a bounded set), keeping order IDs as log fields.
-
Derived metrics
Compute the failure rate with metric math (failed divided by total) for dashboards and alarms.
-
Central view
Link the accounts to a monitoring account with cross-account observability.
Why should customer ID not be used as a dimension on a custom metric?
Show answer
Each unique dimension value creates a separate metric, so high-cardinality values create huge numbers of billed metrics. Put customer IDs in log fields and analyse them with Logs Insights or Contributor Insights.
Exam Tips
Remember for the exam
- A metric is identified by namespace, name and dimensions; use percentiles (p99) for latency, Sum for counts.
- High-resolution metrics (1 s) are kept 3 hours; 1-minute data 15 days; 5-minute 63 days; 1-hour 15 months.
- EC2 basic monitoring is 5-minute; detailed is 1-minute; memory and disk usage need the CloudWatch agent.
- EMF publishes metrics through structured logs without API calls; avoid high-cardinality dimensions.
- Metric math derives values such as error rates; cross-account observability centralises monitoring.