As you know, in AWS we cannot monitor Hard Disk (Volume) and Memory (RAM) through CloudWatch but with few steps, we can monitor and set alarm on it according to our needs. So, in this post we will see, how can we accomplish that.
Step1.
Installation of dependencies (packages and binaries) in order to setup Memory and Disk utilization
RHEL 7
Step2.
Download and configure the "Memory" and "Disk/Volume" script
Create a folder cloudwatch
Step 3.
Create a user cloudwatch user with Programmatic access
Go to IAM and create a user with following details -
Username - cloudwatchuser
Access type - Programmatic access
Permission - CloudWatchFullAccess
Copy the AWS Access ID and AWS Secret Key for next step to configure "awscred.conf"
Now, Paste here the AWSAccessId and AWSSecretKey copy in the last step into the awscreds.conf file
Varify Command
now run the following command to send data to cloudwatch (Disk data)
Disk Utility
To see the all information related CPU, Memory and Disk details in the last 24 hours
Step 4.
For help related to cronjob and other commands
Step 5.
To continuously send the data to CloudWatch. We will set a cronjob
Copy your instance id, Linux System > Filesystem, instanceId, MountPath => selct DiskSpaceUsed
Installation of dependencies (packages and binaries) in order to setup Memory and Disk utilization
RHEL 7
sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA --enablerepo="rhui-REGION-rhel-server-optional" -y
sudo yum install zip unzip -y
Amazon Linux 2 and Amazon Linux AMIsudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64 -y
sudo yum install zip unzip -y
SUSE Linux Enterprise Serversudo zypper install perl-Switch perl-DateTime
sudo zypper install –y "perl(LWP::Protocol::https)"
Debian Based Systems
sudo apt-get update
sudo apt-get install unzip libwww-perl libdatetime-perl
Step2.
Download and configure the "Memory" and "Disk/Volume" script
Create a folder cloudwatch
mkdir cloudwatch
Download the package into the cloudwatch directory
wget https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip
Unzip the downloaded script
unzip CloudWatchMonitoringScripts-1.2.2.zip
Remove the download zip script compress file
rm CloudWatchMonitoringScripts-1.2.2.zip
Now go inside the extracted script directory
cd aws-scripts-mon
Create a copy of awscreds.template to awscreds.conf
cp awscreds.template awscreds.conf
Now edit the copy file and put AWSAccessId and AWSSecretKey
AWSAccessId=AWSSecretKey=
Step 3.
Create a user cloudwatch user with Programmatic access
Go to IAM and create a user with following details -
Username - cloudwatchuser
Access type - Programmatic access
Permission - CloudWatchFullAccess
Copy the AWS Access ID and AWS Secret Key for next step to configure "awscred.conf"
Now, Paste here the AWSAccessId and AWSSecretKey copy in the last step into the awscreds.conf file
Varify Command
./mon-put-instance-data.pl --mem-util --verify --verbose
Original command
./mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --mem-used --mem-avail
The memory commands All in One (this command is same as above command
./mon-put-instance-data.pl --mem-util --mem-used --mem-avail
Disk Utility
./mon-put-instance-data.pl --disk-space-util --disk-path=/dev/xvda1
Disk Space Available
./mon-put-instance-data.pl --disk-space-avail --disk-path=/dev/xvda1
Disk Space Used
./mon-put-instance-data.pl --disk-space-used --disk-path=/dev/xvda1
Disk All in One command
./mon-put-instance-data.pl --disk-space-util --disk-space-used --disk-space-avail --disk-path=/dev/xvda1
./mon-get-instance-stats.pl --recent-hours=24
For help related to cronjob and other commands
./mon-put-instance-data.pl --help
To continuously send the data to CloudWatch. We will set a cronjob
*/5 * * * * /home/gautam/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/dev/xvda1 --from-cron*/5 * * * * /home/gautam/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl --mem-used --disk-space-used --disk-path=/dev/xvda1 --from-cron*/5 * * * * /home/gautam/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl --mem-avail --disk-space-avail --disk-path=/dev/xvda1 --from-cron
Step 6.
Now we are setup alarm for disk usageCopy your instance id, Linux System > Filesystem, instanceId, MountPath => selct DiskSpaceUsed