Skip to content

Instantly share code, notes, and snippets.

@goulon
Created July 7, 2017 19:40
Show Gist options
  • Save goulon/509ecb297bf6bd49060819d5067b584c to your computer and use it in GitHub Desktop.
Save goulon/509ecb297bf6bd49060819d5067b584c to your computer and use it in GitHub Desktop.
#!/bin/bash
while getopts 'w:c:' OPT; do
case $OPT in
w) WARN=$OPTARG;;
c) CRIT=$OPTARG;;
esac
done
WARN=${WARN:=90}
CRIT=${CRIT:=95}
vUsedMemory=$(free -m| grep Mem | awk '{ print int(($3-$7)*100/$2) }' )
if [ "${vUsedMemory}" -ge "${CRIT}" ]
then
echo "MEM CRITICAL - ${vUsedMemory}%"
exit 2
elif [ "${vUsedMemory}" -ge "${WARN}" ]
then
echo "MEM WARNING - ${vUsedMemory}%"
exit 1
else
echo "MEM OK - ${vUsedMemory}%"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment