Configure CloudWatch Agent
The Unified CloudWatch Agent is a utility that is installed on your virtual machine to provide metrics such as: Disk Utilization, Memory Utilization, Swap Usage, and CPU Utilization that are not available to EC2. The CloudWatch Agent enables you to capture custom application and OS metrics allowing you to keep an eye on all of your AWS resources. Refer to the AWS documentation for the full list of Metrics Tracked by CloudWatch Agent.
Step 1 – Download the Package
The URL below has a placeholder for whatever region is closest to you to download the package.
wget https://s3.region.amazonaws.com/amazoncloudwatch-agent-region/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb US-WEST-2 Example wget https://s3.us-west-2.amazonaws.com/amazoncloudwatch-agent-us-west-2/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
Step 2 – Install the Package
After downloading the package, you will need to install it.
sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
Step 3 – Run the Configuration Wizard
The CloudWatch Agent comes with a convenient configuration wizard that will allow you to define which metrics you’d like to track.
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
Step 4 – Install the CollectD Daemon
The CloudWatch Agent comes with an integration for collectD to gather whatever system metrics you’d like. But.. you must first install collectd.
sudo apt-get install collectd
Step 5 – Setup the User / AWS Credentials
It is not recommended to run the CloudWatch Agent as root and it is preferred to use the cwagent user that is created by the package installation. You will need to create a home directory for the user and give it AWS credentials.
Create directories: sudo mkdir /home/cwagent sudo mkdir /home/cwagent/.aws Create your credentials file: sudo vi /home/cwagent/.aws/credentials [default] aws_access_key_id=###################### aws_secret_access_key=##################################### Change folder owner: sudo chown -R cwagent:cwagent /home/cwagent/
Step 6 – Start CloudWatch Agent
The final step to enable reporting is to start the CloudWatch Agent daemon on your system. After starting the daemon, you should start seeing metrics reported in CloudWatch under CWAgent within a few minutes.
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
Troubleshooting
If for some reason you are not seeing the metrics appear in CloudWatch, take a look at the CloudWatch Agent log file and see if you can identify the issue.
sudo tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
Thank You!
Thank you for reading! Feel free to reach out to us if you have any questions, or if you would like Razor Sharp Consulting to help you setup monitoring of your EC2 instances.