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.
- SSH into your EC2 instance
- Install the required dependencies: <ul style="list-style-type: square;">
-
sudo apt-get install unzip && apt-get install libwww-perl && apt-get install libcrypt-ssleay-perl apt-get install libswitch-perl
- Download the monitoring scripts: <ul style="list-style-type: square;">
-
wget http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip
- Extract the contents and remove the zip file: <ul style="list-style-type: square;">
-
unzip CloudWatchMonitoringScripts-v1.1.0.zip
rm CloudWatchMonitoringScripts-v1.1.0.zip
- 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;">
-
cd aws-scripts-mon
echo "AWSAccessKeyId=****" > awscreds.template
echo "AWSSecretKey=****" >> awscreds.template
- Set environment variable & export the path of the credential file <ul style="list-style-type: square;">
-
path=$(pwd) ; export AWS_CREDENTIAL_FILE=${path}/awscreds.template
- 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;">
-
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
- Check the metrics on the AWS console
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
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