[Script] Simple Disk Space Monitoring Alert

Hello Everyone,

Recently, I was tasked to create some simple monitoring scripts using Unix. Well, I must admit that I am not a Unix-expert but being a resourceful Oracle DBA, I was able to create simple monitoring scripts by combining different articles and sources online.

I hope you find some of them useful.

Let's share and make others love Oracle, too.


Disk Space Monitoring Script

######---Start of Script---t#####

#!/bin/bash 
# Report disk space usage

threshold="80" 
i=2 
diskresult=`df -h |grep -v "Filesystem" | awk '{ print $5 }' | sed 's/%//g'` 
for percent in $diskresult; do 
if ((percent > threshold)) 
then
partition=`df -h | head -$i | tail -1| awk '{print $6}'` 
echo "Warning: $partition is ${percent}% used." 
fi 
let i=$i+1 
done

######---End of Script---#####

Note: This Disk Space monitoring script will capture all your mount points that are more than 80% utilized. 

What if I would like to get notified when a mount point reached the 80% threshold? I don't need all the mount points reported, just alert me if a storage as reached the limit.


######---Start of Script---t#####

#!/bin/bash 
# Report disk space usage

threshold="80" 
i=2 
diskresult=`df -h |grep -v "Filesystem" | awk '{ print $5 }' | sed 's/%//g'` 
for percent in $diskresult; do 
if ((percent > threshold)) 
then
partition=`df -h | head -$i | tail -1| awk '{print $6}'` 
echo "Warning: $partition is ${percent}% used." 
fi 
let i=$i+1 
done> /tmp/disk.warning

iFile=/tmp/disk.warning

if [[ -s $iFile ]] ; then
mailx -s "$ORACLE_SID on ${hostname}: Tablespace Warning" gab@lovesoracle.com < /tmp/disk.warning
else
echo "$iFile is empty." > /tmp/noreport

fi ;

######---End of Script---#####

Note: In this modification, the output of the first script will be stored into a text file (/tmp/disk.warning). If there are mount points that reached the threshold, then the file will have entries, otherwise, it will be blank. The added script, in red, will check if the file is empty or not. If the file has contents, then the disk space utilization report for those that reached the threshold will be sent through email. If there none reached the threshold, then it will just echo that the file is empty and redirect the output to a text file (/tmp/noreport).

This is a very simple and readable script. You can make a lot of monitoring scripts from this one. See my other monitoring script articles.

[Script] ASM Diskgroup Space Usage Alert

[Script] Tablespace Usage Alert





Comments

  1. Thank you for sharing these scripts. They are very helpful. Ihope you can share other monitoring scripts too like CPU utilization, IO or maybe database performance. It quite a while since i last visit this blog. And it has new articles now. I hope you will be writing more often soon.

    ReplyDelete

Post a Comment

Popular posts from this blog

RMAN Restoration to New Server with Different Directory and New Database Name

[Script] Tablespace Usage Alert

[Script] ASM Diskgroup Space Usage Alert