CloudWatch Custom Metric Quick Start

What is CloudWatch Custom Metrics

Setting up CloudWatch Custom Metrics on your instance allows you to monitor resources in addition to the default metrics of CPU Utilization, Disk I/O and Network I/O provided by default. Custom Metrics includes the following additional metrics:

memory-used

memory-utilization

memory-available

swap-utilization

swap-used

disk-space-utilization

disk-space-used

disk-space-availability


These steps are written specifically for Ubuntu. The steps vary for different distributions.

  1. SSH into your EC2 instance
  2. Install the required dependencies: <ul style="list-style-type: square;">
  3. sudo apt-get install unzip && apt-get install libwww-perl && apt-get install libcrypt-ssleay-perl apt-get install libswitch-perl
  4. </ul>
    
  5. Download the monitoring scripts: <ul style="list-style-type: square;">
  6. wget http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip
  7. </ul>
    
  8. Extract the contents and remove the zip file: <ul style="list-style-type: square;">
  9. unzip CloudWatchMonitoringScripts-v1.1.0.zip
    rm CloudWatchMonitoringScripts-v1.1.0.zip
  10. </ul>
    
  11. Add access key and secret key to the configuration file. Edit the awscreds.template located inside aws-scripts-mon directory file to add your Access Key and Secret Key. <ul style="list-style-type: square;">
  12. cd aws-scripts-monecho "AWSAccessKeyId=****" > awscreds.template
    echo "AWSSecretKey=****" >> awscreds.template
  13. </ul>
    
  14. Set environment variable & export the path of the credential file <ul style="list-style-type: square;">
  15. path=$(pwd) ; export AWS_CREDENTIAL_FILE=${path}/awscreds.template
  16. </ul>
    
  17. Create a cronjob. Add the monitoring script to the crontab. Run it every 5 minutes or choose a time cycle according to your requirements. <ul style="list-style-type: square;">
  18. echo "*/5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail --swap-util --swap-used --disk-path=/ --disk-space-util --disk-space-used --disk-space-avail" >> /etc/crontab
  19. </ul>
    
  20. Check the metrics on the AWS console

Head over to the CloudWatch console to check the metrics. Goto: https://console.aws.amazon.com/cloudwatch/

Click on Linux System under Metrics. Then click on the instance ID that you want to check the metrics of.

I have largely automated the setup process in the following script. The distributions currently supported are Amazon Linux, Ubuntu and SUSE Linux.

Download the script here: https://github.com/slashr/CloudWatch-Deployment

Comments