Out of the box, CloudWatch by default monitors 4 things:
- CPU
- Network
- Disk
- Status Checks
Can you tell which resource CloudWatch doesn’t monitor out of the box? Memory! (update: According to AWS technical support “Right now, you do not need to deploy anything in you AMI to monitor your instance. Metrics like memory utilization and disk space require us to look into the OS running in the instance and that is why we do not have these valuable metrics. We are looking at ways to provide more insight into your OS and applications and will have more details as we firm up the plans”). Amazon provides 2 articles for doing this, one for most Linux flavors and another for Windows. This article is basically a walkthrough of the Linux article (since I know Windows and want to learn more Linux anyway J )
- Create a CloudWatch role in IAM (if you don’t know how to do this see my previous article)
- Spin up a new Amazon Linux AMI instance using the new CloudWatch role in the IAM section of the instance creation (check out THIS article if you get stuck)
-
SSH into your new instance & run the following command:
- sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https
- curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
- unzip CloudWatchMonitoringScripts-1.2.1.zip
- rm CloudWatchMonitoringScripts-1.2.1.zip
- cd aws-scripts-mon
- sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https
- At this point you have downloaded and unzipped the Perl script necessary to make the remote calls to CloudWatch and installed the Perl bits needed to run said script.
-
Now you can test it by running ./mon-put-instance-data.pl –mem-util –verify –verbose
If all that looks good you can set up a cron job to automate, type in the following commands:
- crontab -e
- */5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl –mem-util –mem-util –mem-used –mem-avail –from-cron
- <escape>
- :wq
This command reports memory and disk space util back to CloudWatch every 5 minutes.
Now to check to see if it worked!
Go to your CloudWatch console:
Click “Metrics” and you should now see Linux System Metrics
Because I just got it going, I don’t have any trending data for the three metrics, but after a few hours of 5 minute polling you’ll get some visibility into how your instances memory is behaving!
Check out this one liner…no perl script required:
http://blog.zorangagic.com/2015/09/create-cloudwatch-memory-metric-on-linux.html
Nice Zoran!!