The Cost Explorer right-sizing recommendation says you can downsize three of the production EC2 instances from m6i.2xlarge to m6i.xlarge and save 30% on their line. The CPU averages over the last 14 days are 22%, 19%, and 26% — clearly the boxes are over-spec. You almost click accept, then you remember the last time someone right-sized on averages and got paged at 14:30 the next Tuesday when the daily report kicked off and the box ran out of headroom. Right-sizing on averages is wrong because averages hide peaks. p95 is the correct measure. Here is the query that surfaces it.
What’s happening
CPU utilization on most application servers is bursty. A box that averages 22% CPU over 14 days is usually idle for most of the period and pinned near 80% for an hour a day. The average smooths the peak into invisibility. Downsizing on the average leaves no headroom for the burst, and the box runs out of CPU during the very window the workload needs it.
The right metric is the 95th percentile — the level the workload reaches or exceeds 5% of the time. p95 catches the daily report, the morning rush, the cron job that fans out at 03:00 UTC. Once you have p95 with one-minute granularity, the right-sizing decision becomes mechanical:
- p95 below 40% → safe to downsize one step (e.g.
m6i.2xlarge→m6i.xlarge) - p95 between 40% and 60% → leave it alone, comfortable
- p95 between 60% and 75% → instrument and watch; near the boundary
- p95 above 75% → upsize, or accept that the next burst will cause an incident
The same logic applies to memory, with the caveat that memory does not graceful-degrade — running out of memory triggers the OOM killer and kills processes, while running out of CPU just makes things slower. For memory, the conservative read is to use p99 and never let it cross 80%.
The same logic applies to disk I/O, network, and iowait, but CPU and memory are the two that drive the right-sizing decision 90% of the time.
How to verify
CloudWatch does not expose percentile statistics on instance-level metrics by default — the only built-in statistics are Average, Maximum, Minimum, Sum, and SampleCount. The right-sizing query needs --extended-statistics 'p95', and it needs the metric to be in detailed (one-minute) monitoring mode. Coarse five-minute averages will report a p95 that is not actually a per-minute p95.
Enable detailed monitoring first if not already:
aws ec2 monitor-instances --instance-ids i-0123456789abcdef0
Then the right-sizing query:
aws cloudwatch get-metric-statistics \
--namespace AWS/EC2 \
--metric-name CPUUtilization \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
--start-time $(date -u -v-14d +%Y-%m-%dT%H:%M:%S) \
--end-time $(date -u +%Y-%m-%dT%H:%M:%S) \
--period 60 \
--extended-statistics p95 \
--query 'Datapoints[].ExtendedStatistics.p95' \
--output text | sort -n | tail -1
The last line of output is the maximum per-minute p95 over the 14-day window. That is the number you decide on, not the dashboard average.
For memory, EC2 does not publish memory metrics natively — you need the CloudWatch agent installed on the instance. Once it is:
aws cloudwatch get-metric-statistics \
--namespace CWAgent \
--metric-name mem_used_percent \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
--start-time $(date -u -v-14d +%Y-%m-%dT%H:%M:%S) \
--end-time $(date -u +%Y-%m-%dT%H:%M:%S) \
--period 60 \
--extended-statistics p99 \
--query 'Datapoints[].ExtendedStatistics.p99' \
--output text | sort -n | tail -1
For a fleet, wrap the per-instance query in a loop driven by aws ec2 describe-instances --filters Name=tag:Environment,Values=production. The output of the loop becomes a sortable table of (instance-id, instance-type, p95-cpu, p99-mem). The right-sizing candidates jump out.
A pattern worth checking: an instance with consistent p95 around 22% across both CPU and memory is a clear over-spec. An instance with CPU p95 at 22% but memory p99 at 78% is memory-bound — downsizing CPU but keeping memory requires switching family (e.g. c6i to r6i), not just size.
The fix
The right-sizing run, on a representative fleet:
-
Pull p95 CPU and p99 memory for every production instance, over a 14-day window covering at least one full business cycle (a calendar week plus the weekend). Cron jobs and weekly reports must be inside the window.
-
Bucket instances by the rules above. Anything in the “p95 below 40%” bucket is a candidate; anything in the “p95 above 75%” bucket is a separate alarm — upsize or shed load.
-
For each downsize candidate, check three additional things before changing:
- Burstable family? If it is a
t3ort4g, the credit balance matters more than p95 CPU. Look atCPUCreditBalance— if it ever bottoms out, the box is silently CPU-throttled and the metric reads low for the wrong reason. - Daily peak alignment. Look at the histogram of CPU by hour-of-day. If the peak is a sharp spike (a cron-driven job) rather than a smooth diurnal pattern, the downsize will catch the spike at a worse position on the curve. Move the job to a separate worker before downsizing the main instance.
- Network and disk i/o. A
m6i.xlargehas lower network and EBS throughput limits than am6i.2xlarge. If the instance is network-bound rather than CPU-bound, the right-size is sideways (to ac6infamily) rather than down.
- Burstable family? If it is a
-
Schedule the resize during the workload’s lowest-traffic window. EC2 instance type changes require a stop/start cycle (a few minutes of downtime on a single instance). For instances behind a load balancer, drain first.
-
Watch the new size for at least one full business cycle before declaring done. The metric to watch is the same p95 query — at the new size, p95 should land in the 40–60% comfort band.
Three rules we hold across every right-sizing engagement:
Right-size one step at a time. Jumping two sizes down is twice the risk for marginally more savings. The first downsize captures most of the gain.
Right-size during a representative period. Right-sizing on a 14-day window that happens to include a holiday week will under-state real load. Pick a window with at least one full business cycle and no major outages.
Do not right-size to “save money” in a vacuum. The savings on a single instance are a small percentage of the bill. The right-sizing work is worth it because it also surfaces over-provisioning patterns that compound across the fleet — and because boxes that run closer to their natural utilization age more predictably.
The whole exercise is mechanical once the p95 query is in your toolbox. The first run takes an afternoon for a 30-instance fleet. The next quarter’s run takes an hour.
Stack Harbor runs fleet-wide p95 right-sizing as part of Cloud Compute onboarding and ongoing Managed Cloud Ops. If your bill is climbing on instances that average idle, start with a fleet review.