Sub topic 4
Statistics, periods, and units
This chapter assumes you know what a metric, a namespace, and a dimension are, and that you can run AWS CLI commands. Here you will learn how CloudWatch turns raw data points into the numbers you read and alarm on.
Statistics
A statistic is an aggregation of the data points that fall inside one period. CloudWatch does not return every raw data point. It returns one value per period for each statistic you request.
The common statistics are:
Average: the sum of values divided by the number of values.Sum: the total of all values.MinimumandMaximum: the lowest and highest values.SampleCount: how many data points arrived.- Percentiles such as
p90orp99, requested with--extended-statistics.
Choose the statistic that matches the question. Average CPU hides a short spike, so use Maximum to find spikes. Use Sum for counters such as request counts. Use a percentile for latency, because an average hides slow outliers.
Periods
A period is the length of time, in seconds, over which CloudWatch aggregates data points. It must be a multiple of 60 for standard-resolution metrics. High-resolution custom metrics also allow 1, 5, 10, or 30 seconds.
A shorter period gives finer detail but more points to read. A longer period smooths noise. Retention also limits what you can ask for. CloudWatch keeps 1-minute data for 15 days and 5-minute data for 63 days. After that, only 1-hour data remains, for up to 15 months. Requests for old data must use a period that matches what is still stored.
Querying statistics
This command returns the average and maximum CPU of one instance in 5-minute periods over one hour:
aws cloudwatch get-metric-statistics \
--namespace AWS/EC2 \
--metric-name CPUUtilization \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
--start-time 2026-11-26T18:00:00Z \
--end-time 2026-11-26T19:00:00Z \
--period 300 \
--statistics Average MaximumThe result contains up to 12 data points, one for each 5-minute period. Each has a Timestamp, the requested statistics, and a Unit. The points are not returned in time order, so sort them yourself if order matters.
Units
A unit labels what a value measures, for example Seconds, Milliseconds, Bytes, Percent, or Count. In put-metric-data you set it with --unit. If you omit it, the unit is None.
CloudWatch does not convert units. It treats data points with different units as separate series within the same metric. If you publish PageLoadTime once in Seconds and once in Milliseconds, a query with --unit Milliseconds will skip the first value. Pick one unit per metric and keep it.
Common errors
- Too many data points:
get-metric-statisticsreturns an error if your time range and period would produce more than 1,440 points. Shorten the range or raise the period. - Empty results: the period is shorter than the metric's publishing interval, or the unit filter does not match.
- Misleading averages: averaging a metric that reports only on events, such as errors, dilutes the result. Use
Suminstead.
Exercise
You publish request latency from a web service and want to catch the slowest 1 percent of requests. Which statistic should you request, and why is Average a poor choice?
Show answer
Request the p99 percentile with --extended-statistics p99. Average blends many fast requests with a few slow ones, so a small group of very slow requests barely changes it.
Exercise
A query for a custom metric with --unit Milliseconds returns fewer data points than you published. What is a likely cause?
Show answer
Some data points were published with a different unit, such as Seconds or no unit. CloudWatch stores each unit as a separate series and the unit filter excludes the others.