Custom CloudWatch Metrics - by Ashutosh

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

9 Thoughts to “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. 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.

Leave a Reply to Akshay Cancel reply

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

5 × 5 =