AWS Linux EC2 instance resource alerting (CPU/Memory/Disk) without Cloudwatch

Phani Kumar
1 min readMar 16, 2021

Monitoring is an important part of maintaining the reliability, availability, and performance of your Amazon Elastic Compute Cloud (Amazon EC2) instances. The use of AWS Cloudwatch service for monitoring could costs if usage reached free tier limits and monitoring of Disk & Memory of EC2 is not straightforward to monitor even using Cloudwatch. The following article tells you how to alert you when the instance reached the prescribed limits using a simple bash shell script generic to all EC2 Linux instances.

Before you execute the following script make sure the IAM role of the instance has policies to publish a message to the SNS topic and to describe tags in order to get the instance given name.

The script goes like this

At line 19 update the disk percentage when the alert need to be send

At line 33 update the CPU & Memory percentages when the alert need to be send

At line 35 update the correct SNS topic ARN

And finally running the above shell script to execute periodically

  1. Login into the instance
  2. create a file to save the above bash script e.g. sudo vi /home/monitor.sh
  3. copy and save the shell script
  4. create a crontab job to execute the file periodically

* * * * * sudo sh /home/monitor.sh

Please follow my other stories to execute the above script without login into the instance using the AWS SSM run command

--

--