Skip to content

Instantly share code, notes, and snippets.

@ivan-loh
Created December 16, 2017 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan-loh/d9d6d55e49254e2baecc307babb4ef40 to your computer and use it in GitHub Desktop.
Save ivan-loh/d9d6d55e49254e2baecc307babb4ef40 to your computer and use it in GitHub Desktop.
script to use to monitor memory utilization
#!/bin/bash
function alert {
curl --header 'Access-Token: <access_token_here>' \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Memory Threshold Reachd","title":"Database Server Alert","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
}
# Checks
THRESHOLD_PERCENTAGE=90
TOTAL=$(grep MemTotal /proc/meminfo | awk '{print $2}')
FREE=$(grep MemFree /proc/meminfo | awk '{print $2}')
let "USED = $TOTAL - $FREE"
let "USED = $USED * 100"
let "USED_PERCENTAGE = $USED / $TOTAL"
echo "USED "$USED_PERCENTAGE
if [ $USED_PERCENTAGE -gt $THRESHOLD_PERCENTAGE ]
then
alert
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment