mirror of
https://github.com/oneoffdallas/pfsense-nagios-checks.git
synced 2024-12-22 17:13:44 +01:00
64 lines
2.4 KiB
Bash
64 lines
2.4 KiB
Bash
#!/bin/sh
|
|
|
|
if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ] ; then
|
|
warn=$2
|
|
crit=$4
|
|
SYSCTL_FILE='/home/nagios/sysctl.temp'
|
|
SYSCTL=$(/sbin/sysctl -a > $SYSCTL_FILE)||exit 3
|
|
#echo $SYSCTL
|
|
TOTAL_MEM=`grep 'hw.physmem:' $SYSCTL_FILE | cut -d":" -f2`
|
|
#echo "total mem" $TOTAL_MEM
|
|
TOTAL_MEM_MB=`expr $TOTAL_MEM / 1024 / 1024`
|
|
#echo "total mem in MB" $TOTAL_MEM_MB
|
|
PAGESIZE=`grep 'hw.pagesize:' $SYSCTL_FILE | cut -d":" -f2`
|
|
#echo "pagesize" $PAGESIZE
|
|
ACTIVE_COUNT=`grep 'vm.stats.vm.v_active_count:' $SYSCTL_FILE | cut -d":" -f2`
|
|
#echo "active_count" $ACTIVE_COUNT
|
|
MEM_ACTIVE=`expr $ACTIVE_COUNT \* $PAGESIZE`
|
|
#echo "mem active" $MEM_ACTIVE
|
|
INACTIVE_COUNT=`grep 'vm.stats.vm.v_inactive_count:' $SYSCTL_FILE | cut -d":" -f2`
|
|
#echo "inactive_count" $INACTIVE_COUNT
|
|
MEM_INACTIVE=`expr $INACTIVE_COUNT \* $PAGESIZE`
|
|
#echo "mem inactive" $MEM_INACTIVE
|
|
CACHE_COUNT=`grep 'vm.stats.vm.v_cache_count:' $SYSCTL_FILE | cut -d":" -f2`
|
|
#echo "cache_count" $CACHE_COUNT
|
|
MEM_CACHE=`expr $CACHE_COUNT \* $PAGESIZE`
|
|
#echo "mem cache" $MEM_CACHE
|
|
FREE_COUNT=`grep 'vm.stats.vm.v_free_count:' $SYSCTL_FILE | cut -d":" -f2`
|
|
#echo "free_count" $FREE_COUNT
|
|
MEM_FREE=`expr $FREE_COUNT \* $PAGESIZE`
|
|
#echo "mem free" $MEM_FREE
|
|
|
|
FREE_MEM=`expr $MEM_INACTIVE + $MEM_CACHE + $MEM_FREE`
|
|
#echo "free mem" $FREE_MEM
|
|
#FREE_MEM_KB=`expr $FREE_MEM / 1024`
|
|
#echo "free mem in KB" $FREE_MEM_KB
|
|
FREE_MEM_MB=`expr $FREE_MEM / 1024 / 1024`
|
|
#echo "free mem in MB" $FREE_MEM_MB
|
|
USED_MEM=`expr $TOTAL_MEM - $FREE_MEM`
|
|
#echo "used mem" $USED_MEM
|
|
USED_MEM_MB=`expr $USED_MEM / 1024`
|
|
#echo "used mem in MB" $USED_MEM
|
|
USED_MEM_PER=`expr $USED_MEM \* 100 / $TOTAL_MEM`
|
|
#echo "used mem %" $USED_MEM_PER
|
|
|
|
if [ $USED_MEM_PER -ge $warn ];then
|
|
if [ $USED_MEM_PER -ge $crit ]; then
|
|
echo "CRITICAL - Memory Usage = $USED_MEM_PER%|MEM=$USED_MEM_PER;;;;"
|
|
exit 2
|
|
else
|
|
echo "WARNING - Memory Usage = $USED_MEM_PER%|MEM=$USED_MEM_PER;;;;"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "OK - Memory Usage = $USED_MEM_PER%|MEM=$USED_MEM_PER;;;;"
|
|
exit 0
|
|
fi
|
|
|
|
else
|
|
echo "check_mem.sh - Nagios Plugin for checking memory usage"
|
|
echo ""
|
|
echo "Usage: check_mem.sh -w <warnlevel> -c <critlevel>"
|
|
exit 3
|
|
fi
|