How we setup AWS disk usage monitoring for EC2 instances
An EC2 instance without enough free disk space, can crash instantly. That’s why having a proper AWS disk usage monitoring system is vital for EC2 instances.
Amazon provides CloudWatch monitoring script for EC2 Linux-based instances. But it requires additional customization to make it effective for disk usage monitoring.
Today we’ll discuss how we setup disk usage monitoring for AWS EC2 instances using CloudWatch.
1. Install CloudWatch monitoring script
The first step is to install the CloudWatch monitoring script in the EC2 instance.
The required perl packages are installed first. Then the CloudWatch script is downloaded and installed:
The two main scripts that are installed are:
- mon-put-instance-data.pl – This script does the data collection. It collects the EC2 metrics such as memory, swap and disk utilization and sends it to the CloudWatch.
- mon-get-instance-stats.pl – This script generates the reports. It queries the CloudWatch and displays the utilization statistics for the EC2 instance for which the script is executed.
2. Assign privileges to AWS user
Every AWS EC2 instance has a user assigned to it, known as the IAM (Identity and Access Management) user.
To execute CloudWatch scripts, this user should be given the required privileges. This can be done from the AWS management console to manage users.
When an access key is created for the user from the AWS console, it will also give a secret key for that user. These two keys are important for CloudWatch configuration.
The access key and the secret key for the user should be specified in the file “awscreds.template”. It may also be given in the command line while executing the scripts.
Once the keys are updated in the template file, the user should now be given the privilege to access the CloudWatch reports.
This is done via the ‘Policies’ feature for Users in the AWS management console. Create a new policy for CloudWatch full access:
Assign this new policy to the IAM user associated with the EC2 instance:
Bobcares provides Outsourced Hosting Support for online businesses. Our services include Outsourced Web Hosting Support, Outsourced Server Support, Outsourced Help Desk Support, Outsource Live Chat Support and Phone Support Services.