Tuesday, January 5, 2010

Disk Usage monitor script

A good Disk Usage monitor in shell script, defining the Operating System and checking within threshold :

#!/bin/sh

BDEVLIST="/,90,88,85,80"

RHLINUX_DF=/bin/df
SUN_DF=/usr/xpg4/bin/df
SCO_DF=/bin/df


HOST_OS=`uname -s`
HOST_NAME=`hostname`
STATE=5

case $HOST_OS in
Linux )
DF=$RHLINUX_DF
;;
SunOS )
DF=$SUN_DF
;;
SCO_SV )
DF=$SCO_DF
;;
*)
DF=df
;;
esac

for i in $BDEVLIST
do
BDEV=`echo $i | cut -d "," -f 1`
DU_CRITICAL=`echo $i | cut -d "," -f 2`
DU_MAJOR=`echo $i | cut -d "," -f 3`
DU_MINOR=`echo $i | cut -d "," -f 4`
DU_WARNING=`echo $i | cut -d "," -f 5`
TEMPSTR=`$DF -P $BDEV | grep -v Filesystem | awk '{ print $5 }'`
USED_SP=`basename $TEMPSTR %`

if [ $USED_SP -ge $DU_CRITICAL ]
then
STATE=1
ALARM="The storage on \"$BDEV\" partition reached a critical value ($USED_SP %); this might be due to some extra files. Please check if some log files are growing too fast or if there are some large unused files that can be deleted, you may check the Debug Level of the main processes and also inform the system administrator. In case no action is taken, the system will be seriously affected."
else
if [ $USED_SP -ge $DU_MAJOR ]
then
STATE=2
ALARM="The storage on \"$BDEV\" partition is a major issue ($USED_SP %); some log files could be growing too fast, or some large unused files must be deleted; please contact your system administrator. If this alarm remains not cleared, the leak of storage on this partition could be a critical issue and the system will be affected."
else
if [ $USED_SP -ge $DU_MINOR ]
then
STATE=3
ALARM="The storage on \"$BDEV\" partition is still minor ($USED_SP %), some log files could be growing fast or some unused files need to be cleaned. Please check large files on this partition and contact your system administrator. Please consider this alarm seriously in order to prevent any increase in its severity."
else
if [ $USED_SP -ge $DU_WARNING ]
then
STATE=4
ALARM="This is just a warning alarm to inform you that the storage on \"$BDEV\" partition is increasing ($USED_SP %); you need to check large files and inform the system administrator. Kindly take this alarm into consideration in order to prevent any increase in its severity."
else
ALARM="The storage on \"$BDEV\" partition is normal ($USED_SP %), it is below the warning level."
fi
fi
fi
fi

STRING="$STRING DISK_STORAGE_\"$BDEV\" $ALARM"

done

echo "$STATE $STRING"

0 Comment :