
AWS Custom Cloudwatch Alarm in AWS-Ubuntu-Linux
Let us create custom alarm for disk space utilization metric on EBS Volume of EC2 instances with following steps.
- cd /tmp
- wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon- cloudwatch-agent.rpm
- sudo rpm -U amazon-cloudwatch-agent.rpm
- In IAM, you need to select necessary Role and attach necessary policy for CloudWatch
- Take backup of files under /opt/aws/amazon-cloudwatch-agent/etc/
- Run – sudo nano /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
- 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”
}
}
}
- sudo systemctl restart amazon-cloudwatch-agent
- sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status
- “status” : “running” should appear
- tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
- Any error should not appear in the log
- 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 default
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
- You will get confirmation mail for new topic, you should confirm and few minutes status pending confirmation will go
- In the alarm screen, blue line for disk usage and red line for threshold should appear
- If disk usage is equal or greater (based on condition given), status goes into alarm, alarm email will be sent
Good Luck
– Kuppuram, CTO, We3cares