- Newest
- Most votes
- Most comments
Install and configure the CloudWatch agent on your EC2 instance to collect disk space metrics. View these metrics in the CloudWatch dashboard and set up alarms for low disk space notifications. This provides continuous monitoring and automated alerts.
Hi DC,
please try this solution it will be helpful for you.
Step1 Install the CloudWatch Agent on Your EC2 Instances
Connect to Your EC2 Instance:
1. Use SSH to connect to your EC2 instance.
Step2 Download and Install the CloudWatch Agent:
1. For Amazon Linux or Ubuntu, run the following commands
sudo yum install amazon-cloudwatch-agent -y
or
sudo apt-get install amazon-cloudwatch-agent -y
Step3 Create the CloudWatch Agent Configuration File:
- Create a JSON configuration file (/opt/aws/amazon-cloudwatch- agent/bin/config.json)
{
"agent": {
"metrics_collection_interval": 60,
"logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
},
"metrics": {
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
},
"metrics_collected": {
"disk": {
"measurement": [
"used_percent"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
}
}
}
}
Step4 Start the CloudWatch Agent:
Run this commands.
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
Step 5: Configure CloudWatch Alarms
1.Open the CloudWatch Console:
Go to the AWS Management Console and open the CloudWatch console.
2.Create an Alarm:
In the left navigation pane, click on Alarms, then click Create alarm.
3.Select the Metric:
Click on Select metric, then choose CWAgent -> Per-Instance Metrics -> Disk. Select the used_percent metric for the appropriate instance.
4.Configure the Alarm:
Specify the conditions for the alarm. For example: Threshold type: Static Whenever Disk used_percent is Greater/Equal to 80 percent Datapoints to alarm: 1 out of 1
5.Set Up Actions:
Add a notification by selecting an existing SNS topic or creating a new one. This will allow you to receive email notifications when the alarm state is triggered.
6.Name and Create the Alarm:
Provide a name for the alarm and review the configuration. Click on Create alarm.
Step 6 Monitor and Respond to Alerts
1.View Disk Usage:
Go to the CloudWatch dashboard to see the disk usage metrics for your EC2 instances.
2.Receive Notifications:
When the disk usage exceeds the threshold, you'll receive an email notification (if configured).
Please look at AWS Document Link you will get more information.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-alarms.html
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch.html
Wow, thank you Parthasaradi this is very helpful ! I am going to review this thoroughly! Best Regards, Donald
Relevant content
- asked a year ago
- asked a year ago

Thank you for your quick reply and help Osvaldo! Best Regards, Donald