1+
Read Time:2 Minute, 5 Second

Today, we will learn how to create custom CloudWatch metrics like RAM Usage and Disk Usage in centos 7?

What made me do this and why it is important?

Let’s see monitoring is a very important part of maintaining our servers. Also, AWS didn’t support these monitoring scripts for Centos. This made it difficult for a system administrator to monitor the environment.

Monitor RAM and Disk Usage in CentOS 7

A little bit about a script:

Script Name: mon-put-instance-data.pl

Purpose: This script is written in pearl and is used to collect metrics of swap, disk, and memory. In this blog, we will create custom CloudWatch metrics for RAM and disk.

Well, you are at the right place, because I’m going to show you how it’s done.

Prerequisite:

  • Centos 7
  • AWS IAM role with EC2 and CloudWatch access. You need to attach the role to your centos instance.

Creating custom CloudWatch Metrics (Centos 7)

    1. Install the following packages:
      sudo yum install perl-Switch perl-DateTime perl-Sys-Syslogperl-LWP-Protocol-https perl-Digest-SHA perl-LWP-Protocol-https -y
    2. We also need zip and unzip tools:
      sudo yum install zip unzip -y
    3. Download the monitoring scripts:
      curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
    4. Run the below commands to install the script:
      unzip CloudWatchMonitoringScripts-1.2.1.zip
      rm CloudWatchMonitoringScripts-1.2.1.zip
      cd aws-scripts-mon
    5. To verify the scripts are working enter this command:
      ./mon-put-instance-data.pl --mem-util --verify --verbose
    6. Now, let make this command automated by running it in crontab:
      crontab -e
    7. Enter these cronjob commands to send RAM and Disk Usage to AWS CloudWatch:
      Note: Instead of “/home/centos” enter your directory where you have installed the script. In the disk-path enter the mounted path of the volume whose metrics you want. In this case, I want metrics of the root EBS volume.

      */5 * * * * /home/centos/aws-scripts-mon/mon-put-instance-data.pl --mem-used --mem-util --mem-avail
      */5 * * * * /home/centos/aws-scripts-mon/mon-put-instance-data.pl --disk-path=/ --disk-space-util --disk-space-avail --disk-space-used
      
    8. Go to CloudWatch console and Create a new dashboard.
    9. Click on Add widget option and then select Linux system Metrics.

      Here you have it the screenshot of custom CloudWatch metrics:

      Custom CloudWatch Metrics
      Custom CloudWatch Metrics

      Feel free to comment and contact me for more blogs.

      Reference: AWS Monitoring, Blog by AWS

About Post Author

Ashutosh

Hi, my name is Ashutosh Maheshwari and I'm a DevOps Engineer. I have 4 years of experience in AWS, Linux, Shell Scripting and DevOps technologies. I love to learn new things and Share it with the community.
1+

13 thoughts on “Custom CloudWatch Metrics (CentOS 7)

  1. Really good post It would help to monitor memory and disk metrics which AWS didn’t provide by default…..

    Awaiting same another post….which will make easier sys admin work….

    1+
    1. Hello Max,
      These are also great alternatives. As you have mentioned them in the comment I don’t think I need to add them to the blog. BTW AWStats is a great tool too.

      0
  2. Mate. i expected failure and have been poorly mistaken. you have done a nice job.
    some notes:
    im running centos 7 and by doing a bit more searching found it also necessary to add the user secure key and ID number. find the file “awscreds.template” copy it and rename it to “awscreds.conf”. edit that document and add in the user ID and secure Key.
    you must create a new user in AWS IAM. – note the secure key show once and can not be seen again. it shows at the end of making a user and giving that user admin rights. you can make a group or just give that user admin rights.
    and then you also need to get the tool – yum install perl-LWP-Protocol-https
    it does not work without it.
    then you can test it working and uploading with – ./mon-put-instance-data.pl –mem-util –mem-used-incl-cache-buff –mem-used –mem-avail

    1+
  3. great how-to, thanks (from a Linux beginner) – for me it didn’t work though until I installed this:
    sudo yum install perl-LWP-Protocol-https
    Only then did the Linux System metrics showed up in CW dashboard
    I discovered this by running the script manually like:
    ./mon-put-instance-data.pl --disk-path=/ --disk-space-util --disk-space-avail --disk-space-used

    Which gave the following error:

    ERROR: Failed to call CloudWatch: HTTP 501. Message: LWP will support https URLs if the LWP::Protocol::https module
    is installed.

    1+

Leave a Reply

Your email address will not be published. Required fields are marked *

eight + four =

Close