The unified CloudWatch agent collects memory, swap and disk usage, and can also ship log files. It replaces the older monitoring scripts.
- Attach an IAM role with the managed policy
CloudWatchAgentServerPolicyto the instance. - Install and configure:
sudo yum install -y amazon-cloudwatch-agent
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
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
A minimal configuration:
{ "metrics": { "metrics_collected": {
"mem": { "measurement": ["mem_used_percent"] },
"disk": { "measurement": ["used_percent"], "resources": ["/"] } } } }
The metrics appear under the CWAgent namespace. Alarm on mem_used_percent and disk used_percent the same way as CPU. Custom metrics are charged per metric, so collect only what you will alarm on.