script to monitorize counter errors

muzzol

Active Member
Dec 2, 2009
43
0
26
hi,

i've been working on a zimbra-proxmox environment and i've created this simple script to check errors on /proc/user_beancounters

can be used in nagios or in any other monitoring system

feel free to add it to wiki or any other place.


Code:
#!/bin/bash

# script for checking system counters on a openvz container
# must be executed inside the container and is mainly focused
# on using it with nagios
#
# feel free to use it and modify it
#
# àngel "muzzol" bosch - 02-06-2011 - muzzol@gmail.com

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

if [ ! -r /proc/user_beancounters ]; then
    echo "ERROR: File /proc/user_beancounters doesn't exist or can't be readed"
    exit $STATE_CRITICAL
fi

COUNTERS=`cat /proc/user_beancounters | grep -v "Version: " | grep -v "uid  resource" | sed 's/.*kmemsize/ kmemsize/'`

IFS=$'\n'
  
for c in $COUNTERS ; do
    COUNTER=`echo "$c" | tr -s " " | cut -d" " -f2`
    VALUE=`echo "$c" | tr -s " " | cut -d" " -f7`
      
    if [ "$VALUE" != "0" ]; then
	echo "WARNING: errors in counter $COUNTER"
	exit $STATE_WARNING
    fi
done

echo "OK: No errors found in counters"

exit $STATE_OK