Monday, March 1, 2010

Monitoring file system free space in UNIX

As most of the times Apps Technical/DBA person’s responsibility to monitor UNIX file system to ensure none of the UNIX file system mount points becomes full. If Oracle DBA creates table spaces with the auto extended option then it’s required to monitor UNIX file system instead of ORACLE. Whenever table-spaces are allowed to grow within the UNIX mount point, we must be always cautious to make sure that the file system does not become full.

Using df –k command we can see all the mount points, here is the example






root> df -k


Filesystem                  kbytes        used         avail         capacity   Mounted on
/dev/dsk/rootvol       3009327       1653629    1295512    57%           /               
/proc                        0                   0            0              0%            /proc
mnttab                      0                   0            0              0%            /etc/mnttab
fd                              0                  0             0              0%           /dev/fd
/dev/dsk/rutdsk_1     191611          5985       166465      4%            /global/.devices/node@1


Normally all oracle file system starts with /u0 to minimize the complexity, you can add greep command. Here is the example


root> df -k grep /u0


/dev/uat03/ou01      62914560     53979734        8376410        87%    /5u_ofi_app/u01
/dev/uat03/ou01      107063296   93965411        12346000       89%    /5z_ofi_db/u01
/dev/uat03/o02        107063296   102682991      4213089        97%    /5z_ofi_db/u02
/dev/uat03/ou03      107063296   97055884        9405053        92%    /5z_ofi_db/u03
/dev/uat03/ou04      31457280     27704043        3518713        89%    /5z_ofi_db/u04
/dev/uat03/1-L01     31457280     9159293          20906241      31%    /5z_olp_db/u01


Instead of monitoring manually you can create script to monitor the same and run job using crontab so that it will not required to connect UNIX filesytem and monitor.

Below is one script, u can change according to your requirement


#!/bin/sh
#
#set -xv
LIMIT=90
MAIL_RECIPIENT='asm-support@domain.com'
limit_reached()
{
echo "
==============================================
WARNING : Filesystem threshold reached the $LIMIT% limit !!
MOUNTPOINT : $MOUNTPOINT
FILESYSTEM : $FILESYSTEM
SIZE(GB) : $SIZE_GB
USED(GB) : $USED_GB
FREE(MB) : $AVAIL_MB
CAPACITY(%) : $CAPACITY
==============================================
"
}
df -k
grep -v Filesystem
while read FILESYSTEM KBYTES USED_KB AVAIL_KB CAPACITY MOUNTPOINT
do
PCT_USED=`echo $CAPACITY
cut -d% -f1`
SIZE_GB=`expr $KBYTES / 1048576`
USED_GB=`expr $USED_KB / 1048576`
AVAIL_MB=`expr $AVAIL_KB / 1024`
if [ $PCT_USED -gt $LIMIT ]
then
limit_reached
limit_reached
mailx -s "FS : $MOUNTPOINT is $CAPACITY Full !!" $MAIL_RECIPIENT
fi
done