The CloudWatch agent collects metrics that aren’t available by default, most importantly memory utilization. Your instance’s IAM role, attached in Step 3 with the AmazonSSMManagedInstanceCore policy, means it’s already registered as a Systems Manager managed instance, so we can install and configure the agent remotely, with no SSH connection and no cost beyond the Free Tier.



InstallAmazonCloudWatchAgentlatest
ec2-rightsizing-lab instance checked. Scroll further down and select Run.



sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
The wizard asks a long series of questions. Follow the table below in order and give the exact answer shown — answering “yes” on the StatsD/CollectD questions is the most common way people break the config before the agent ever starts, since CollectD needs a package we don’t have installed:
| Wizard question | Answer to give |
|---|---|
| On which OS are you planning to use the agent? | 1 (linux) |
| Are you using EC2 or On-Premises hosts? | 1 (EC2) |
| Which user are you planning to run the agent? | 2 (root) |
| Do you want to turn on StatsD daemon? | 2 (no) |
| Do you want to monitor metrics from CollectD? | 2 (no) |
| Do you want to monitor any host metrics? e.g. CPU, memory, etc. | 1 (yes) |
| Do you want to monitor cpu metrics per core? | 1 (yes) |
| Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if the info is available? | 1 (yes) |
| Do you want to aggregate ec2 dimensions (InstanceId)? | 1 (yes) |
| Would you like to collect your metrics at high resolution (sub-minute resolution)? | 4 (60s) |
| Which default metrics config do you want? | 1 (Basic) |
| Are you satisfied with the above config? | 1 (yes) |
| Do you have any existing CloudWatch Log Agent configuration file to import for migration? | 2 (no) |
| Do you want to monitor any log files? | 2 (no) |
| Do you want to monitor journald logs? | 2 (no) |
| Do you want the CloudWatch agent to also retrieve X-ray traces? | 2 (no) |
| Do you want to store the config in the SSM parameter store? | 2 (no) |




The generated config should show a "mem": { "measurement": ["mem_used_percent"], ... } block alongside "disk" under metrics_collected — this confirms mem_used_percent is enabled, the metric Compute Optimizer needs for a full recommendation (see Step 8).

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s
You should see Configuration validation succeeded near the end of the output, with no error lines.

sudo systemctl status amazon-cloudwatch-agent
You should see Active: active (running).

If step 10 fails instead with an error like open /usr/share/collectd/types.db: no such file or directory, see the Troubleshooting section at the bottom of this page before continuing.


disk_used_percent across all 9 mount points for your instance — the same way you’d select the mem_used_percent row to graph memory.
Now that the CloudWatch agent is installed and running, CloudWatch can track memory utilization for this instance — the missing piece needed for AWS Compute Optimizer to give you a full, accurate recommendation.
If step 10 fails with an error like:
Error running agent: Error loading config file /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml: error parsing socket_listener, open /usr/share/collectd/types.db: no such file or directory
it means the wizard’s CollectD question was answered “yes” at some point, which added a collectd block to the config that depends on a file the collectd package (not installed on Amazon Linux 2023) would normally provide.
Fix it by removing that block instead of installing collectd, since we don’t actually need it for this lab:
sudo nano /opt/aws/amazon-cloudwatch-agent/bin/config.json
"collectd": { ... } block inside "metrics_collected" and delete it entirely (remove any trailing comma left behind so the JSON stays valid). Save with Ctrl+O, Enter, then exit with Ctrl+X.sudo systemctl status amazon-cloudwatch-agent should show active (running).If you’d rather start clean instead of hand-editing JSON, just re-run the wizard (step 9) from scratch — this time answering no to both the StatsD and CollectD questions — and then re-run step 10.
Installing and running the agent through Systems Manager is free. The only thing that could cost money is publishing a very large number of custom metrics — this lab publishes just a handful, well within the CloudWatch Free Tier of 10 custom metrics per month.