Sub topic 4
Statistics, periods, and units
This chapter assumes you know what a CloudWatch metric, namespace, and dimension are, and that you can run the AWS CLI against an account where you have CloudWatch permissions. Here you will learn how CloudWatch turns raw data points into the single numbers you see on graphs and in alarms.
Why a metric needs a statistic
A metric is a stream of data points. A data point is one measurement with a timestamp, a value, and optionally a unit. CloudWatch never shows you every data point. It groups them into time buckets and reduces each bucket to one number. Two settings control that reduction:
- The period is the length of each bucket, in seconds.
- The statistic is the function that turns the bucket's data points into one value.
Picking a different statistic or period gives you a different answer from the same data. That is why an alarm can stay quiet while users complain: the statistic or period may hide the problem.
The available statistics
| Statistic | What it returns | Typical use |
|---|---|---|
| Average | Sum divided by SampleCount | CPU, latency trends |
| Sum | Total of all values | Request counts, bytes transferred |
| Minimum | Lowest value | Detecting dips, such as free capacity |
| Maximum | Highest value | Catching short spikes |
| SampleCount | Number of data points | Checking whether data arrived |
| pNN (for example p99) | Value below which NN percent of data points fall | Tail latency |
Percentiles are called extended statistics. On the CLI you request them with --extended-statistics instead of --statistics. CloudWatch also offers trimmed mean (for example TM90), which discards the top 10 percent of values before averaging. Percentiles are not available for metrics that contain negative values.
Choose the statistic to match what the metric means:
- A counter such as
RequestCountor an error count is usually read with Sum. Average would show the average batch size, which is rarely useful. - A gauge such as CPU utilization is read with Average or Maximum. Average shows the trend, and Maximum shows spikes.
- Latency is best read with a percentile. Average latency can look healthy while 1 percent of users wait for seconds.
To turn a Sum into a rate, divide it by the period. A Sum of 3,000 requests in a 300-second period is 10 requests per second.
Periods and resolution
A standard-resolution metric has data points at 1-minute granularity or coarser. For these metrics the period must be 60 seconds or a multiple of 60. A high-resolution metric, which you publish with a storage resolution of 1 second, also supports periods of 1, 5, 10, or 30 seconds.
CloudWatch keeps data but reduces its detail as it ages:
| Data point granularity | Available for |
|---|---|
| Under 60 seconds | 3 hours |
| 60 seconds | 15 days |
| 300 seconds (5 minutes) | 63 days |
| 3,600 seconds (1 hour) | 455 days (15 months) |
If you ask for a 60-second period over data older than 15 days, you get 5-minute detail at best. Spikes older than that are averaged away, so export or alarm on them while the data is still fine-grained.
Many AWS services publish at 5-minute intervals by default. EC2 does this unless you turn on detailed monitoring, which gives 1-minute data. If you set a 60-second period on a 5-minute metric, most buckets are empty. An alarm on that metric then sees missing data, so match the period to how often the metric is published.
Querying a statistic
The command below asks for the 99th percentile and the sample count of a custom latency metric in 1-minute periods.
aws cloudwatch get-metric-statistics \
--namespace MyApp \
--metric-name PageLoadTime \
--dimensions Name=Service,Value=checkout \
--start-time 2026-11-26T18:00:00Z \
--end-time 2026-11-26T19:00:00Z \
--period 60 \
--statistics SampleCount \
--extended-statistics p99 \
--unit MillisecondsPoints to note:
- Dimensions are an exact match. If you published the metric with
Service=checkoutonly, adding another dimension returns nothing, because that is a different metric. - A single call returns at most 1,440 data points. A 60-second period over 24 hours is exactly 1,440. Longer ranges need a larger period or several calls.
- The
--unitoption filters the results to data points published with that unit. - Periods with no data points are left out of the response. Gaps are not returned as zeros.
Publishing pre-aggregated data
If your application records thousands of values per minute, you do not need to send each one. You can publish a statistic set: the Sum, Minimum, Maximum, and SampleCount for a batch of values.
aws cloudwatch put-metric-data \
--namespace MyApp \
--metric-name PageLoadTime \
--dimensions Service=checkout \
--unit Milliseconds \
--statistic-values Sum=2300,Minimum=120,Maximum=480,SampleCount=10CloudWatch can compute Average from this (230 ms) and merge it with other data points in the same period. It cannot compute percentiles from a statistic set, because the individual values are gone. If you need percentiles, publish individual values.
Units
Every data point can carry a unit, such as Seconds, Milliseconds, Bytes, Percent, Count, or Bytes/Second. If you leave the unit out, CloudWatch records None. Units matter for three reasons:
- Graphs and the console label the axis from the unit.
- CloudWatch does not convert between units. A value of 1
Secondsand a value of 1000Millisecondsare stored as-is. - If you publish the same metric with two units, CloudWatch keeps them as separate series within the same metric. A query without
--unitmay mix them in one bucket, and the Average becomes meaningless.
Pick one unit per metric and use it in every publisher.
Choosing a statistic and period for an alarm
An alarm applies a statistic over a period and compares the result to a threshold. The same settings apply as for queries. This alarm watches the p99 of the latency metric.
aws cloudwatch put-metric-alarm \
--alarm-name checkout-slow-p99 \
--namespace MyApp \
--metric-name PageLoadTime \
--dimensions Name=Service,Value=checkout \
--extended-statistic p99 \
--period 60 \
--evaluation-periods 5 \
--datapoints-to-alarm 3 \
--threshold 800 \
--comparison-operator GreaterThanThreshold \
--treat-missing-data notBreachingChoosing the values:
- A short period reacts quickly but is noisy. A long period smooths noise but delays detection by up to one period.
- Use Maximum to catch any spike, Average to ignore brief ones.
- Percentile alarms on metrics with very few data points per period are unreliable. With only 3 samples in a period, p99 is just the maximum.
- Set the period to match the metric's publish interval, never below it.
Common errors
- Empty results. The period is shorter than the publish interval, the dimensions do not match exactly, or the time range is outside the retention window for that period.
- Invalid period. Standard-resolution metrics reject periods that are not multiples of 60.
- Sum used on a gauge. Summing CPU percentages across a period gives numbers above 100 that mean nothing.
- Mixed units. Two publishers use
SecondsandMillisecondsfor one metric name, and the Average is wrong.
Exercise
A service publishes one request-latency data point per request, with unit Milliseconds. An alarm uses Average over a 5-minute period and never fires, but users report that about 2 percent of requests take over 5 seconds. Which change would make the alarm detect this, and why can you not build the same view from a statistic set?
Show answer
Switch the alarm to a high percentile such as p99 (--extended-statistic p99). Average is pulled down by the many fast requests, but p99 reflects the slowest 1 percent to 2 percent, so the slow requests move the value. A statistic set holds only Sum, Minimum, Maximum, and SampleCount. The individual values are not stored, so CloudWatch cannot compute a percentile from it. To alarm on p99 you must publish individual values.
Exercise
You query a standard-resolution metric over the last 30 days with a period of 60 seconds. What do you get, and what should you change?
Show answer
Data points older than 15 days are no longer stored at 60-second granularity, so you get no 1-minute detail for that older part. Use a period of 300 seconds or more for ranges that old. Also, 30 days of 60-second periods is 43,200 points, which exceeds the 1,440-point limit per get-metric-statistics call, so a larger period or several calls are needed.