The answer is to use AWS CloudWatch alarms. They are free level compliant and have a nice toolbar. Detailed setup is described internally by this documentation guide , but I suggest you follow my steps to make sure this works for you.
The first thing you need to do is Launch a new instance of Ubuntu EC2, which can be written to CloudWatch . This is due to the new IAM role with permissions. (you cannot attach a new role to an existing instance - see second Note: here .). You no longer need to run an EC2 instance to change IAM roles. See announcement .
The next step you perform is: Install authoring perl AWS scripts that allow you to write to CloudWatch. Add a new cron to record to CloudWatch every five minutes.
Finally, create a new alarm in the CloudWatch console to send you an email when memory usage exceeds a certain threshold.
Below are the steps for each of the phases listed above:
Install authoring perl scripts for AWS
- SSH into your new instance and run the following commands:
$ sudo apt-get update
$ sudo apt-get install unzip
$ sudo apt-get install libwww-perl libdatetime-perl
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
- Verify that your perl scripts were installed correctly using the following command
./mon-put-instance-data.pl --mem-util --verify --verbose
- Add to cron, a perl script command that puts the amount of memory used by the ubuntu instance in CloudWatch
crontab -e
*/5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-util --from-cron
- Wait about 20 minutes for statistics to be added to CloudWatch.
Create a new alarm in the CloudWatch console
- In the AWS console, select CoudWatch and click on the Blue, Performance Overview button.
- On the right side of the screen, you should see the All indicators tab at the bottom of the screen and a link to the Linux system. Click "Linux System" and then "Instance" and you will see the MemoryUtilization label.
- Click MemoryUtilization , and then go to the Grapted Metrics tab at the bottom.
- On the right here you will see the Alarm icon.

- Click this icon to create an alarm. Set a threshold for emailing you if your memory usage is greater than 40.
- Add stress to the instance and you will see that the email has arrived. I used the
stress command found in this answer and it worked. Type stress and ubuntu will show you how to set stress. Below is a screenshot of the memory usage in CloudWatch that I created for this entry. I get an email every time memory usage crosses 40 percent.

Hope this helps.
source share