AWS Custom Cloud-watch Alarm in AWS-Ubuntu-Linux

AWS Custom Cloud-watch Alarm in AWS-Ubuntu-Linux

Let us create custom alarm for disk space utilization metric on EBS Volume of EC2 instances with following steps.

1. cd /tmp

2. wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazoncloudwatch-agent.rpm

3. sudo rpm -U amazon-cloudwatch-agent.rpm

4. In IAM, you need to select necessary Role and attach necessary policy for CloudWatch

5. Take backup of files under /opt/aws/amazon-cloudwatch-agent/etc/

6. Run – sudo nano /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json

7. Copy and Paste the following JSON string in amazon-cloudwatch-agent.json, change value for InstanceId and save

{
 "agent": {
 "metrics_collection_interval": 60,
 "run_as_user": "cwagent"
 },
 "metrics": {
 "metrics_collected": {
 "disk": {
 "measurement": [
 "used_percent"
 ],
 "resources": [
 "*"
 ],
 "drop_device": false
 }, 
 "processes": {
 "measurement": [
 "running",
 "sleeping",
 "dead"
 ]
 }
 },
 "append_dimensions": {
 "InstanceId": "i-xxxxxxxxxxxx"
 }
 }
 }

8. sudo systemctl restart amazon-cloudwatch-agent

9. sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status a. “status” : “running” should appear

10. tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log

11. Any error should not appear in the log

12. Open AWS Management Console, go to CouldWatch, select Alarms, Click “Create Alarm” and click “Select Metric”

Click Create Alarm
Click Select metric
Click CW Agent
Click device…
Select xvda1
Click Select metric
Go with defaults
Select as given in the above image and click Next
Give Topic Name and email as preferred and click Next
Provide Alarm name and description as preferred and click Next
Then, Preview and Click Create alarm. Done

13. You will get confirmation mail for new topic, you should confirm and few minutes status pending confirmation will go off.

14. In the alarm screen, blue line for disk usage and red line for threshold should appear

15. If disk usage is equal or greater (based on condition given), status goes into alarm, alarm email will be sent

Good Luck

– Kuppuram, CTO, Nixserv.in