Sub topic 2
Measuring real utilization with CloudWatch
Right-sizing starts with measurement. This chapter shows which CloudWatch metrics describe how busy an EC2 instance is, which of them you must add yourself, and how to read the data without being misled by averages.
It assumes you can run AWS CLI commands, know what an EC2 instance, instance type and AMI are, and have met CloudWatch metrics, namespaces and dimensions. It also assumes you can SSH into a Linux instance.
What CloudWatch gives you for free
EC2 publishes metrics to the AWS/EC2 namespace without any setup. These metrics come from the hypervisor, the layer that runs outside your operating system. That has two consequences. They cost nothing, and they cannot see inside the guest. The hypervisor knows how much CPU time your instance used, but it does not know how much memory your processes hold.
| Metric | Unit | What it tells you | Right-sizing use |
|---|---|---|---|
| `CPUUtilization` | Percent | Share of allocated vCPU time in use | Main signal for CPU headroom |
| `NetworkIn`, `NetworkOut` | Bytes per period | Traffic through the instance's network interfaces | Check against the instance type's bandwidth |
| `NetworkPacketsIn`, `NetworkPacketsOut` | Packets per period | Packet rate | Detect packet-rate limits on small instances |
| `EBSReadBytes`, `EBSWriteBytes` | Bytes per period | Traffic to attached EBS volumes | Check against the instance's EBS bandwidth |
| `EBSReadOps`, `EBSWriteOps` | Operations per period | EBS I/O request count | Check against the instance's EBS IOPS |
| `DiskReadBytes`, `DiskWriteBytes` | Bytes per period | Instance store traffic only | Ignore on instances without instance store |
| `CPUCreditBalance` | Credits | Remaining burst credits (T-family only) | Detect burstable instances running out of credits |
| `StatusCheckFailed` | Count | Health check result | Not a sizing signal |
The Disk* metrics are a common trap. They measure instance store volumes, not EBS. On an instance that uses only EBS they read zero, which does not mean the disk is idle. Use the EBS* metrics for EBS-backed volumes.
What CloudWatch does not give you
EC2 does not publish memory usage or filesystem usage by default. Both are central to right-sizing. A database server might use 5% CPU and 90% of its RAM. If you judged it by CPU alone, you would move it to a smaller instance and break it.
To get these metrics, install the CloudWatch agent on the instance. The agent runs inside the guest operating system and publishes to the CWAgent namespace. The instance needs an IAM role that includes the CloudWatchAgentServerPolicy managed policy.
Here is a minimal agent configuration that collects memory and root filesystem usage every 60 seconds:
{
"agent": {
"metrics_collection_interval": 60
},
"metrics": {
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
},
"metrics_collected": {
"mem": {
"measurement": ["mem_used_percent"]
},
"disk": {
"measurement": ["used_percent"],
"resources": ["/"]
}
}
}
}Save it as /opt/aws/amazon-cloudwatch-agent/etc/config.json, then load it and start the agent:
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
-a fetch-config -m ec2 \
-c file:/opt/aws/amazon-cloudwatch-agent/etc/config.json -sAfter a few minutes, confirm that the metrics exist and check which dimensions they carry:
aws cloudwatch list-metrics \
--namespace CWAgent \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0The memory metric is mem_used_percent, and the filesystem metric is disk_used_percent. The disk metric also carries path, device and fstype dimensions. When you query it later, you must supply the exact dimension set that list-metrics shows. CloudWatch treats each distinct dimension set as a separate metric.
Where each signal comes from
Resolution and retention
CloudWatch stores metrics at different resolutions and keeps them for different lengths of time.
| Data point age | Resolution kept |
|---|---|
| 0 to 15 days | 1 minute (if published at 1-minute granularity) |
| 15 to 63 days | 5 minutes |
| 63 days to 455 days | 1 hour |
EC2 sends basic monitoring data every 5 minutes at no charge. Detailed monitoring sends 1-minute data for an additional fee. The agent metrics above use 60-second collection, which is billed as custom metrics.
For right-sizing, 5-minute data is usually enough, because you want sustained patterns, not second-by-second spikes. Detailed monitoring helps when you suspect short, sharp bursts, such as a batch job that saturates the CPU for two minutes.
Retention affects how you plan. If you wait until the instance is already a problem, you only have the data CloudWatch kept. Collect at least two weeks, and preferably a full business cycle. A month-end reporting job will not appear in a window that ends on the 20th.
Reading CPU data
Fetch the CPU data for one instance over two weeks:
aws cloudwatch get-metric-statistics \
--namespace AWS/EC2 \
--metric-name CPUUtilization \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
--start-time 2026-11-01T00:00:00Z \
--end-time 2026-11-15T00:00:00Z \
--period 3600 \
--statistics Average MaximumThe command returns one data point per hour, each with an Average and a Maximum. Two limits apply. get-metric-statistics returns at most 1,440 data points per call, so a 14-day window at a 3,600-second period (336 points) fits, but a 14-day window at a 60-second period (20,160 points) does not. Also, the period must be a multiple of 60, and for data older than 15 days it must be a multiple of 300.
Interpret the two statistics together:
- A low
Averagewith a lowMaximummeans the instance is idle most of the time and is a clear right-sizing candidate. - A low
Averagewith a highMaximummeans short bursts. Sizing to the average would throttle those bursts. Decide whether the bursts matter to users. - A high
Averagemeans the instance is busy. Right-sizing may point to a larger size or a different family.
Why percentiles beat the maximum
The maximum is a single value, and one anomalous minute can set it. The average hides everything. A percentile sits between them. The 95th percentile (p95) is the value that 95% of data points fall below. You request percentiles with extended statistics:
aws cloudwatch get-metric-statistics \
--namespace AWS/EC2 \
--metric-name CPUUtilization \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
--start-time 2026-11-01T00:00:00Z \
--end-time 2026-11-15T00:00:00Z \
--period 3600 \
--extended-statistics p95 p99Note that p95 over hourly periods is the p95 of the 5-minute samples inside each hour. It is not the p95 of the whole two weeks. To get a single figure for the whole window, use a period equal to the window or compute the percentile yourself over the returned points.
A common rule of thumb is to size so that p95 or p99 CPU sits comfortably below your target ceiling, often 60% to 70%, leaving room for growth and failover load. Treat the figure as a starting point, not a law.
Reading several metrics in one call
get-metric-data retrieves many metrics at once and supports metric math. This is the better tool when you need CPU, memory and network side by side. Save the following as queries.json:
[
{
"Id": "cpu_p95",
"MetricStat": {
"Metric": {
"Namespace": "AWS/EC2",
"MetricName": "CPUUtilization",
"Dimensions": [{"Name": "InstanceId", "Value": "i-0123456789abcdef0"}]
},
"Period": 300,
"Stat": "p95"
}
},
{
"Id": "mem_max",
"MetricStat": {
"Metric": {
"Namespace": "CWAgent",
"MetricName": "mem_used_percent",
"Dimensions": [{"Name": "InstanceId", "Value": "i-0123456789abcdef0"}]
},
"Period": 300,
"Stat": "Maximum"
}
},
{
"Id": "net_in",
"MetricStat": {
"Metric": {
"Namespace": "AWS/EC2",
"MetricName": "NetworkIn",
"Dimensions": [{"Name": "InstanceId", "Value": "i-0123456789abcdef0"}]
},
"Period": 300,
"Stat": "Sum"
},
"ReturnData": false
},
{
"Id": "net_in_mbps",
"Expression": "net_in * 8 / PERIOD(net_in) / 1000000",
"Label": "NetworkIn Mbps"
}
]Run it:
aws cloudwatch get-metric-data \
--metric-data-queries file://queries.json \
--start-time 2026-11-01T00:00:00Z \
--end-time 2026-11-15T00:00:00ZThe net_in query returns bytes summed over each 300-second period. The expression multiplies by 8 to get bits, divides by the period length to get bits per second, and divides by one million to get megabits per second. That unit matches how AWS publishes network bandwidth for instance types. Setting ReturnData to false hides the intermediate series so only the converted value comes back.
Burstable instances need extra care
T-family instances (such as t3 and t4g) earn CPU credits while below their baseline and spend them when above it. For these, CPUUtilization alone is misleading. An instance can show 20% CPU because it has run out of credits and is being held to its baseline. Check these metrics too:
CPUCreditBalance: if it trends toward zero, the instance is starved.CPUSurplusCreditsCharged: if it is above zero in unlimited mode, you are paying extra for sustained CPU use. In that case a fixed-performance family such asmorccan be cheaper.
Common mistakes
- Using too short a window. Two days of data miss weekly and monthly patterns. Use at least 14 days.
- Reading only the average. An average of 8% can hide a nightly peak at 90%.
- Ignoring memory. Without the agent, you have no memory data. A "low CPU" instance may be memory-bound.
- Using
Disk*metrics for EBS. They report instance store only. - Mixing periods. Comparing a 5-minute maximum with a 1-hour maximum from different calls gives inconsistent results.
- Judging a fleet by one instance. Instances behind a load balancer can differ. Query several, or aggregate by Auto Scaling group.
- Forgetting instance-level limits. Network and EBS throughput are capped by instance type. A busy instance may hit a bandwidth cap while CPU looks calm.
Putting it together
For each candidate instance, record a small set of figures over the same window: CPU p95 and maximum, memory maximum, network Mbps p95, and EBS throughput and IOPS p95. Add the instance type's limits next to them. The next chapter uses this table as the input to a repeatable right-sizing method.
Exercise
An instance shows a 14-day CPUUtilization Average of 9% and a Maximum of 94%. Memory from the CloudWatch agent peaks at 35%. Name two things you should check before you decide to move it to a smaller size, and say why each matters.
Show answer
First, check how often and for how long the CPU reaches the high values, for example by requesting p95 and p99 and looking at the hourly pattern. A single spike may be ignorable, while a nightly job that reaches 94% for an hour would be throttled on a smaller instance. Second, check whether the instance is a burstable T-family type and, if so, read CPUCreditBalance and CPUSurplusCreditsCharged. Low average CPU on a burstable instance can mean it is being held at baseline after running out of credits. Memory at 35% suggests memory is not the limit, but you should also check network and EBS throughput against the smaller type's limits.
Exercise
You run get-metric-statistics with a 60-second period over a 14-day window and the call fails. Why does it fail, and what are two ways to fix it?
Show answer
A 14-day window at 60-second resolution needs 20,160 data points, but get-metric-statistics returns at most 1,440 per call. You can raise the period (for example to 900 seconds gives 1,344 points, or 3,600 gives 336), or split the window into several shorter calls. You can also use get-metric-data, which allows more data points per request and supports pagination.