This article will help you to monitor EC2 Linux instance memory and disk metrics with AWS CloudWatch. Remember this will not work on any Linux machine outside the EC2 network.

Prerequsiteis

For this tutorial, you will use the Perl scripts provided by AWS team, These scripts have some dependencies. You can use the following commands to install these dependencies as per your operating systems. Redhat Based Systems: Debian Based Systems: SUSE Linux Enterprise Server

Download and Configure Script

The AWS official team provides CloudWatch monitoring scripts. You can simply download the scripts and configure on your system. Use the following command to download scripts and extract on your system. Now create credentails file with coping template file. Now, You need to add AWSAccessKeyId and AWSSecretKey of your AWS account. This will verify account ownership for the script. If you don’t have, you can create keys in your account under Users » Security credentials section.

Test and Schedule Scripts

At this point, your setup is complete. Let’s use the following command to verify the connectivity between script and your AWS account. The output will be something like below on successful verification. As verification has been successfully completed. You can add the script to crontab to run on a regular interval to send data to your ec2 account. Edit crontab and add the following command to run on every 5 minutes.

View Metrics in CloudWatch

You should wait for some time after adding crontab. So it can collect some data to view in metrics graph. After some time

Login AWS Dashboard » Go to CloudWatch Service » Click on Browse Metrics button » Select Linux System under Custom Namespaces. Now, select any metrics to view data in Graph as shown in below screenshot.

Find Utilization Report Command Line

You can also find the resouces utilization statistics for the last 24 hours. Use the following command to get details. The output will be something like below:

How to Monitor Memory and Disk Metrics for AWS Linux Instance - 13