Installing and Configuring the CloudWatch Agent
This lesson explains the unified CloudWatch agent, the standard answer whenever a question needs memory, disk or process metrics, or application log files, from EC2 instances and on-premises servers.
Learning outcomes
After completing this lesson, you will be able to:
- Identify what the agent collects.
- Grant permissions and distribute configuration through Parameter Store.
- Troubleshoot missing agent metrics and logs.
What the agent collects
The agent collects metrics that the hypervisor cannot see, such as mem_used_percent, swap_used_percent, disk_used_percent per mount point, disk I/O, network statistics, TCP connection counts and, with procstat, per-process CPU and memory. Metrics go to the CWAgent namespace by default. It also tails log files and Windows event logs and sends them to CloudWatch Logs, and it can receive StatsD and collectd metrics and OpenTelemetry or X-Ray traces from applications.
Permissions, configuration and installation
The agent needs three things. First, credentials: on EC2 an instance profile role with the CloudWatchAgentServerPolicy managed policy (add AmazonSSMManagedInstanceCore to manage it with Systems Manager); on premises an IAM user profile or IAM Roles Anywhere. Second, a configuration file in JSON with agent, metrics and logs sections, created with the configuration wizard or by hand and usually stored in Parameter Store with a name starting with AmazonCloudWatch-. Third, network access to the CloudWatch (monitoring) and CloudWatch Logs (logs) endpoints through an internet gateway, NAT gateway or interface VPC endpoints.
For a fleet, install the agent with Systems Manager Run Command (AWS-ConfigureAWSPackage with the package name AmazonCloudWatchAgent) and apply the configuration with AmazonCloudWatch-ManageAgent, which reads the configuration from Parameter Store. A State Manager association repeats this on a schedule so that new instances, including those launched by Auto Scaling, are configured automatically. The configuration can add append_dimensions such as AutoScalingGroupName and InstanceId, and aggregation_dimensions to publish group-level metrics.
{
"agent": {"metrics_collection_interval": 60},
"metrics": {
"namespace": "CWAgent",
"append_dimensions": {"AutoScalingGroupName": "${aws:AutoScalingGroupName}", "InstanceId": "${aws:InstanceId}"},
"aggregation_dimensions": [["AutoScalingGroupName"]],
"metrics_collected": {
"mem": {"measurement": ["mem_used_percent"]},
"disk": {"measurement": ["used_percent"], "resources": ["/"]}
}
},
"logs": {"logs_collected": {"files": {"collect_list": [
{"file_path": "/var/log/app/app.log", "log_group_name": "/app/prod", "log_stream_name": "{instance_id}",
"retention_in_days": 90}
]}}}
}The following diagram shows the three requirements around an instance.

Deploying the agent to a fleet
Troubleshooting the agent
When agent metrics or logs do not appear, work through the common causes in order. The following list gives the checks and where to look.
-
Is the agent running?
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status. -
Did it load the configuration?
Check
/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.logfor parse errors or wrong file paths. -
Does the role allow it?
The instance role needs
CloudWatchAgentServerPolicy; AccessDenied errors appear in the agent log. -
Can it reach the endpoints?
Private subnets need a NAT gateway or interface endpoints for
monitoringandlogs. -
Are you looking in the right place?
Metrics are in the
CWAgentnamespace with the appended dimensions, not inAWS/EC2.
Where are the metrics?
Memory metrics for an Auto Scaling group
A team needs to scale a group on memory. They store the configuration above in Parameter Store as AmazonCloudWatch-linux-web, attach CloudWatchAgentServerPolicy and AmazonSSMManagedInstanceCore to the instance profile in the launch template, and create a State Manager association that runs AWS-ConfigureAWSPackage and then AmazonCloudWatch-ManageAgent on every instance tagged Role=web every 30 minutes. Because the configuration aggregates on AutoScalingGroupName, CloudWatch receives a group-level mem_used_percent metric, and a target tracking policy uses it with a target value of 70.
Where should the agent configuration be stored for a fleet of instances?
Show answer
In Parameter Store, from which Systems Manager deploys it to every instance.
Exam Tips
Remember for the exam
- Memory, disk and process metrics need the CloudWatch agent; they appear in the CWAgent namespace.
- The instance role needs CloudWatchAgentServerPolicy.
- Store agent configuration in Parameter Store and deploy it with Systems Manager.
- Private subnets need NAT or interface endpoints for monitoring and logs.
- Use aggregation_dimensions to publish Auto Scaling group-level agent metrics.