Created
June 11, 2019 14:36
-
-
Save jazzl0ver/699719623c3523ecc03ffd2b0cacbb02 to your computer and use it in GitHub Desktop.
Check mounted partitions' usage space on an EC2 instance and alert thru AWS SNS if it's greater than MAX_USAGE percents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Check mounted partitions' usage space on an EC2 instance and alert thru AWS SNS if it's greater than MAX_USAGE percents | |
| # | |
| #-- Set the SNS topic ARN here | |
| TOPIC_ARN="" | |
| MAX_USAGE=90 | |
| [ "$TOPIC_ARN" = "" ] && { echo "SNS topic ARN is not set, exiting.."; exit; } | |
| EC2_AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone` | |
| EC2_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed 's/[a-z]$//'`" | |
| [ "$EC2_REGION" = "" ] && { echo "EC2 region is unknown, exiting.."; exit; } | |
| for j in $(df -h | grep -E "/dev/x|/dev/n" \ | |
| | awk '{print $1,$5}' \ | |
| | sort -u \ | |
| | cut -f2 -d' ' \ | |
| | sed -e 's/%//g' \ | |
| | sort -u); do | |
| [ $j -gt $MAX_USAGE ] && echo -e "One of the volumes have reached ${MAX_USAGE}% of usage:\n\n$(df -h)" \ | |
| | aws --region $EC2_REGION sns publish --topic-arn $TOPIC_ARN --subject "ALARM: host $(hostname) is lack of disk space" --message file:///dev/stdin &>/dev/null | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment