#!/bin/bash # Plugin to monitor free ram disk space. # uses the output of `free` to find the percentage of memory used # # Copyright Notice: GPL # Author: Marian Anderson if [ $# -ne 4 ] && [ "$1" != "-h" ] ; then echo -e "\nUsage $0 -w -c \n" exit; fi if [ "$1" == "-h" ] ; then case $1 in "-h" ) cat << EOF Copyright (c) 2014 Marian Anderson. Parameter List :: -w = Memory usage to activate a warning message (eg: -w 90,25 ). -c = Memory usage to activate a critical message (eg: -c 95,50 ). -h = This Menu :). EOF ;; esac exit; fi # Amount of ram that is being used. used_ram_space=`free | grep Mem | awk '{print $3/$2 * 100.0}' | cut -c1-2` # Error return values ok=0; warning=1; critical=2; unknown=3; if [ $used_ram_space -le $2 ]; then echo "OK - $used_ram_space% total used ram" exit $ok; elif [ $used_ram_space -gt $2 ] && [ $used_ram_space -le $4 ]; then echo "WARNING - $used_ram_space% total used ram" exit $warning elif [ $used_ram_space -gt $4 ]; then echo "CRITICAL - $used_ram_space% total used ram" exit $critical else echo "UNKNOWN - $used_ram_space% total used ram" exit $unknown fi exit;