MOON
Server: Apache
System: Linux cl1170g 4.19.62-mod-std-ipv6-64-rescue #828825 SMP Tue Jul 30 13:54:49 UTC 2019 x86_64
User: wh0f20bb (1057)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //lib/nagios/plugins/check_mem.sh1
#!/bin/bash
# Nagios plugin to check memory consumption
# Excludes Swap and Caches so only the real memory consumption is considered
. /usr/lib/nagios/plugins/utils.sh
# Original de Georg M. Sorst (http://blog.vergiss-blackjack.de/2010/04/nagios-plugin-to-check-memory-consumption/(
# Modificado por Javier de Posada para reportar el estado en el mensaje de salida
# http://javierin.com/2010/09/29/plugin-para-nagios-que-ignora-la-cache-de-memoria-check_mem/
WARN=80
CRIT=90
SWARN=80
SCRIT=90
while getopts "c:w:s:S:h" ARG; do
        case $ARG in
                w) WARN=$OPTARG;;
                c) CRIT=$OPTARG;;
                s) SWARN=$OPTARG;;
                S) SCRIT=$OPTARG;;
                h) echo "Usage: $0 -w <ram warning>% -c <ram critical>% -s <swap warning>% -S <swap critical>%"; exit;;
        esac
done
 
MEM_TOTAL=`free | fgrep "Mem:" | awk '{print $2}'`;
MEM_USED=`free | fgrep "/+ buffers/cache" | awk '{print $3}'`;
SWP_TOTAL=`free | fgrep "Swap" | awk '{print $2}'`;
SWP_USED=`free | fgrep "Swap" | awk '{print $3}'`;
RAMPC=$(($MEM_USED*100/$MEM_TOTAL));
SWPPC=$(($SWP_USED*100/$SWP_TOTAL));
 
if [ $RAMPC -gt $CRIT -o $SWPPC -gt $SCRIT ]; then
        echo "CRITICAL:  RAM: ${RAMPC}% ($((($MEM_USED)/1024)) of $((MEM_TOTAL/1024)) MB) used";
        echo "          SWAP: ${SWPPC}% ($((($SWP_USED)/1024)) of $((SWP_TOTAL/1024)) MB) used";
        exit $STATE_CRITICAL;
elif [ $RAMPC -gt $WARN -o $SWPPC -gt $SWARN ]; then
        echo "WARNING:  RAM: ${RAMPC}% ($((($MEM_USED)/1024)) of $((MEM_TOTAL/1024)) MB) used";
        echo "         SWAP: ${SWPPC}% ($((($SWP_USED)/1024)) of $((SWP_TOTAL/1024)) MB) used";
        exit $STATE_WARN;
else
        echo "OK:  RAM: ${RAMPC}% ($((($MEM_USED)/1024)) of $((MEM_TOTAL/1024)) MB) used";
        echo "    SWAP: ${SWPPC}% ($((($SWP_USED)/1024)) of $((SWP_TOTAL/1024)) MB) used";
        exit $STATE_OK;
fi