Disk Space Usage Monitor

Dilbert once said; let's save disks space by using 8 point fonts and I said, let's save more space by not writing to the disks.

Prevention is better than a cure therefore, adding a script to monitor the disks space on a Linux Server or database is an excellent plan. Taking proactive approach makes the life of an administrator easier. 100 percent disk utilization may hang or bring the Sever down. Administrator can monitor the growth of  disks space and send email/text notification when the disks space are nearly full. This alert notification will give DBA/SYS administrator enough time to clean up data, archive big files or request for more disk space.

The script below monitors Linux Server disk space and sends disk space
WARNING at 80% percent usage and CRITICAL alert when 90% or more utilization is reached.

Script: disks_space_usage.ksh
#Reading only the Usage percent, Mount point for each line from df -h command and then assigning those values to the variables
DF=$(df -h)
df -h|grep -v Mounted| awk '{ print $5 " " $6 }' | while read output; do;
MOUNTPOINT=$(echo $output | awk '{ print $2}')
USAGE=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)
# After entering the loop generated from df -h output, compare USAGE with thresholds
if [ $USAGE -ge $WARNING ]; then
# Check if USAGE is greater than the CRITICAL threshold
   if [ $USAGE -ge $CRITICAL ]; then
      echo -e "$DF\n\nSpace usage script Location $HOST:/home/your_directory/disk_space_usage.ksh" | mailx -s "CRITICAL ALERT: Mount point $MOUNTPOINT in server $HOST has $USAGE% usage" ${TO_EMAIL}
# The Usage is only greater than WARNING threshold
   echo -e "$DF\n\nSpace usage script $HOST:/home/your_directory/disk_space_usage.ksh" | mailx -s "CRITICAL ALERT: Mount point $MOUNTPOINT in server $HOST has $USAGE% usage" ${TO_EMAIL}
# Program End
echo $RC
exit $RC

The script is highly configurable to your need. You can configure those threshold settings for CRITICAL and WARNING and the email address of alert recipient. Whenever the disk space hit the threshold, it sends the alert message to your email. It also sends email with the output of "df -h" in the email body and the mount point name along with the usage % on the subject. How cool is this script for your hot Linux box that you configured recently?

Interested in working with me? I can be reached at pbaniya04[at] for any questions, consulting opportunities or you may drop a line to say HELLO. Thank your again for visiting my blog and looking forward to serving you more.

Have a Database-ious Day!

1 comment

Powered by Blogger.