Archive · AWS

CloudWatch Agent: Memory and Disk Metrics

Install the unified CloudWatch agent on EC2 to report what the default metrics miss.

1 min read

  • CloudWatch Agent
  • Amazon Linux 2
  • IAM role CloudWatchAgentServerPolicy

The unified CloudWatch agent collects memory, swap and disk usage, and can also ship log files. It replaces the older monitoring scripts.

  1. Attach an IAM role with the managed policy CloudWatchAgentServerPolicy to the instance.
  2. 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.