The CloudWatch agent will not work properly without the permissions configured. This was the fastest way I found to get CloudWatch talking correctly.
- Create IAM Role – https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-iam-roles-for-cloudwatch-agent-commandline.html
- Attach Role to EC2 instance – https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/attach-iam-role.html
Install Cloudwatch on the EC2 instance
- Install CloudWatch Agent
sudo yum install amazon-cloudwatch-agent -y
- Install
collectd
(optional)
You probably wantcollectd
installed – https://www.collectd.org/.
It looks like it allows for a bunch of customizations.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-custom-metrics-collectd.html - Navigate to the configuration wizard
cd /opt/aws/amazon-cloudwatch-agent/bin/
- Run configuration wizard
sudo ./amazon-cloudwatch-agent-config-wizard
- Start CloudWatch Agent
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
Additional Commands
- tail CloudWatch agent logs
tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
- Restart CloudWatch agent
sudo systemctl restart amazon-cloudwatch-agent