Trending News
By using our website, you agree to the use of our cookies.

Blog

How to Monitor Amazon EC2 Linux Instance Memory and Disk Metrics
How To

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.

Requirements

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.

RedHat Systems:

				
					sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA
sudo yum install zip unzip
				
			

Debian Systems:

				
					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)"
				
			

Script Configuration

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
				
			
Now, using the coping template file, create a credentials file.
				
					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.

Verify Connectivity

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.

  1. Log in to AWS Dashboard
  2. Navigate to CloudWatch Services
  3. Select Browse Metrics.
  4. Under Custom Namespaces, select Linux System.

Now, as seen in the picture below, select any statistic to display data in Graph.

How to Monitor Amazon EC2 Linux Instance Memory and Disk Metrics yehiweb banner

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.

				
					./mon-get-instance-stats.pl --recent-hours=24

				
			

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%
				
			
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on reddit
Share on vk
Share on tumblr
Share on skype
Share on stumbleupon
Share on whatsapp
Share on email

Related posts

Leave a Reply