Optimize

Enabling EC2 Memory Metrics for Accurate Rightsizing

Install the CloudWatch agent so DigiUsher can read EC2 memory utilization, and make sure that the read-only IAM role of DigiUsher can read those metrics. Without memory data, the rightsizing recommendations use only CPU, network, and disk, and they can propose a smaller instance than a memory-aware analysis supports.

Amazon EC2 sends the CPU, network, and disk metrics to CloudWatch by default. It does not send the memory metrics. Memory is a metric of the operating system, and the hypervisor cannot see it. The memory metrics become available only after you install the CloudWatch agent on the instance. Until that time, the recommendation engine of DigiUsher has no memory signal. It then sizes the instance from the CPU, network, and disk metrics alone, and it can propose a smaller instance than a memory-aware analysis supports.

This page gives the full path:

  • Install the agent.
  • Configure the agent to send the memory metrics.
  • Make sure that the data arrives in CloudWatch.
  • Make sure that the read-only role of DigiUsher can read the data.
  • Make sure that the memory data appears in DigiUsher.

Time to accurate recommendations

After the memory data starts to arrive, wait for 15 full days of history. This is approximately 360 hours in a window of 30 days. Before that time, the memory-based rightsizing is not statistically significant. The recommendations become better as the history grows.

Prerequisites

  • An IAM role that you can attach to the instance, or an instance profile that you can edit.
  • SSM access to the instance, or shell access for the installation by hand.
  • A connected DigiUsher AWS data source. Read Connecting an AWS account and the Permissions Reference.

Setup

Give the instance permission to publish metrics

The agent needs its own permission to write the metrics. Attach the AWS-managed policy CloudWatchAgentServerPolicy to the IAM role of the instance, which is the instance profile. If you store the agent configuration in the SSM Parameter Store, also add AmazonSSMManagedInstanceCore.

This is separate from DigiUsher's permissions

This role lets the agent write to CloudWatch. Steps 1 to 5 cover it. The role of DigiUsher lets DigiUsher read from CloudWatch. Step 6 covers that role.

Install the CloudWatch agent

Option A is SSM. Use it for a fleet of instances. The AWS-ConfigureAWSPackage document installs AmazonCloudWatchAgent on many instances, and you do not open a shell.

Option B is the installation by hand, on a single instance with Amazon Linux 2 or Amazon Linux 2023:

sudo yum install -y amazon-cloudwatch-agent

On Ubuntu and Debian, download the .deb package for your architecture from the AWS package location. Then install it with dpkg -i. Windows uses the MSI package.

Configure the agent to emit memory

Create an agent configuration that collects mem_used_percent. The configuration must append the InstanceId dimension under the CWAgent namespace. DigiUsher and AWS Compute Optimizer use this dimension to match the memory data to the instance. If the dimension is absent or has another name, the memory data has no link to the instance.

/opt/aws/amazon-cloudwatch-agent/etc/config.json:

{
  "metrics": {
    "namespace": "CWAgent",
    "append_dimensions": {
      "InstanceId": "${aws:InstanceId}"
    },
    "metrics_collected": {
      "mem": {
        "measurement": ["mem_used_percent"],
        "metrics_collection_interval": 60
      },
      "disk": {
        "measurement": ["used_percent"],
        "resources": ["*"],
        "metrics_collection_interval": 60
      }
    }
  }
}

Names are case-sensitive

The namespace and the metric names are case-sensitive. Use CWAgent and mem_used_percent exactly.

Start the agent and make sure that it runs

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
  -a fetch-config -m ec2 -s \
  -c file:/opt/aws/amazon-cloudwatch-agent/etc/config.json

# Confirm status is "running"
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status

A correct result gives "status": "running".

Make sure that the metric is in CloudWatch

Make sure that the data point exists. In the CloudWatch console, open Metrics → All metrics → CWAgent → InstanceId and look for mem_used_percent for your instance.

You can also use the CLI. Replace the region and the instance ID:

# Does the metric exist for this instance?
aws cloudwatch list-metrics \
  --namespace CWAgent \
  --metric-name mem_used_percent \
  --dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
  --region us-east-1

# Are data points landing?
aws cloudwatch get-metric-statistics \
  --namespace CWAgent \
  --metric-name mem_used_percent \
  --dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
  --start-time 2026-07-13T00:00:00Z \
  --end-time 2026-07-14T00:00:00Z \
  --period 3600 --statistics Average Maximum \
  --region us-east-1 --output table

If list-metrics returns nothing, look at the namespace and the InstanceId dimension again. Also make sure that the agent runs. Steps 3 and 4 cover these points.

Make sure that the DigiUsher IAM role can read the metric

DigiUsher reads the metrics with a read-only role. This role has cloudwatch:Get* and cloudwatch:List*, which cover ListMetrics, GetMetricData, and GetMetricStatistics. The memory metrics are in the same CWAgent namespace that DigiUsher already reads for the other CloudWatch data. Usually you therefore need no new permission. Make sure that the access exists.

  1. Make sure that the DigiUsher role is attached to the account that owns the instance. Read the Permissions Reference.
  2. Make sure that the read-only policy on that role has cloudwatch:ListMetrics, cloudwatch:GetMetricData, and cloudwatch:GetMetricStatistics, or the wildcards cloudwatch:Get* and cloudwatch:List*.
  3. Make sure that the role itself can read the metric. Assume the DigiUsher read role and run the list-metrics call from step 5 again. If the call returns mem_used_percent, DigiUsher can read it.
aws sts assume-role \
  --role-arn arn:aws:iam::<ACCOUNT_ID>:role/<DigiUsher-ReadOnly-Role> \
  --role-session-name du-mem-check
# then, with the returned temporary credentials, re-run the Step 5 list-metrics call

If the console shows the metric in step 5 but the DigiUsher role does not, the cause is IAM. Correct the policy. DigiUsher shows the memory data only after that correction.

Make sure that the memory data appears in DigiUsher

After the role can read the metric, DigiUsher collects the memory data in the next collection cycle. The rightsizing recommendations then use the memory data, and not only the CPU, network, and disk data. Before you trust the memory-based sizing, wait for 15 days of history. For an instance that is memory-bound, the recommendations become more conservative.

Rolling out across a fleet

  • Use SSM State Manager to keep the agent installed and configured on every instance, and to configure a new instance automatically.
  • For an Auto Scaling group, add the agent and the configuration to the launch template or the AMI. A new instance then sends the memory data from the first boot.

Troubleshooting

SymptomLikely causeFix
No memory in DigiUsherAgent not installed or not runningSteps 2 and 4
Metric missing in CloudWatchInstanceId dimension absent or renamed, or wrong namespaceStep 3. Use CWAgent and InstanceId exactly
Metric in console but not in DigiUsherDigiUsher role has no read access, or is not on this accountStep 6
"Insufficient data" or an unchanged recommendationFewer than 15 days of memory historyWait for the collection window (Step 7)
Custom-metric charges appear on the billCloudWatch bills custom metrics by storage and by API callThis is expected. Collect only the metrics that you need

If you have a question, write to support@digiusher.com.

On this page