How to Monitor Amazon EC2 Linux Instance Memory and Disk Metrics
Monitor Amazon EC2 Linux Instance
Most monitoring metrics are provided by default by AWS CloudWatch. It does not, however, include any metrics for memory consumption or disc space usage. So, if you want to use CloudWatch to monitor your system’s System memory or free disc space. Then you first need to add these metrics with custom scripts to your account.
Table of Contents
This tutorial will show you how to use AWS CloudWatch to monitor EC2 Linux instance memory and disc metrics. Keep in mind that this will not function on any Linux machine outside of the Amazon EC2 network.
The Perl scripts provided by the AWS team will be used in this tutorial. These scripts are dependent on each other. You may install these dependencies using the instructions below, depending on your operating system.
sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA sudo yum install zip unzip
sudo apt-get update sudo apt-get install unzip libwww-perl libdatetime-perl
SUSE Linux Enterprise Server:
sudo zypper install perl-Switch perl-DateTime sudo zypper install –y "perl(LWP::Protocol::https)"
CloudWatch monitoring scripts are provided by the AWS official team. You can simply download and configure the scripts on your machine. To download scripts and extract them on your machine, use the command below.
cd /opt wget http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip unzip CloudWatchMonitoringScripts-1.2.1.zip
cd /opt/aws-scripts-mon cp awscreds.template awscreds.conf
You now need to add your AWS account’s AWSAccessKeyId and AWSSecretKey. This will verify the script’s account ownership. You can generate keys in your account under Users >> Security credentials if you don’t have them.
Your setup is complete at this point. To verify the script’s connection with your AWS account, use the following command.
./mon-put-instance-data.pl --mem-util --verify --verbose
On successful verification, the output will look like this.
Verification completed successfully. No actual metrics sent to CloudWatch.
Verification has been completed successfully. You may use crontab to schedule the script to send data to your ec2 account on a routine basis. Add the following command to crontab and execute it every 5 minutes.
*/5 * * * * /opt/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron
Check Metrics in CloudWatch
After adding crontab, you should wait for a little. As a result, it may collect data to display on a metrics graph. After some time has passed.
- Log in to AWS Dashboard
- Navigate to CloudWatch Services
- Select Browse Metrics.
- Under Custom Namespaces, select Linux System.
Now, as seen in the picture below, select any statistic to display data in Graph.
Command-Line for Getting a Utilization Report
You can also see the data for the last 24 hours of resource usage. To acquire further information, type the following command.
The following is an example of the output:
Instance i-xxxxxxxxxxxxxx statistics for the last 12 hours. CPU Utilization Average: 0.05%, Minimum: 0.03%, Maximum: 1.56% Memory Utilization Average: 10.63%, Minimum: 10.62%, Maximum: 10.63% Swap Utilization Average: N/A, Minimum: N/A, Maximum: N/A Disk Space Utilization for /dev/xvda1 mounted on / Average: 6.65%, Minimum: 6.65%, Maximum: 6.65%
Top 6 Tips on Getting One of the Highest Paying Jobs in Oregon: Make Sure You Stand Out Among the Crowd
Job hunting is more than applying for vacant positions and waiting for interviews. It is a demanding task that requires…