LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-02-2011, 12:36 PM   #1
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Rep: Reputation: 0
Disk space alert


Hi All,

I have a few servers running and would like to set an alert to let me know when the disk space is close to be full.

Can anyone suggest a solution ? Thanks.
 
Old 09-02-2011, 12:46 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
You could set up a job in cron on each server to check periodically and send you an email.

Or, you could set up a central host that ssh's to a list of server and checks, then notifies you of any that are nearing your threshold.

Or, you could set up something like Nagios http://www.nagios.org/.
 
1 members found this post helpful.
Old 09-02-2011, 01:52 PM   #3
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 44
One small problem with doing

Quote:
You could set up a job in cron on each server to check periodically and send you an email.

is if the disk space fills before your cron job runs you wont get an email because it wont have the tmp space to compose the mail. Nagios is good to monitor disk space.
 
Old 09-02-2011, 04:22 PM   #4
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Original Poster
Rep: Reputation: 0
I installed Nagios and looking at it now. But I'm really confused. Looking for a help guide of some sort just to get an overview

Got the install instructions from here if any is interested: http://nagios.sourceforge.net/docs/3...rt-fedora.html
 
Old 09-02-2011, 07:42 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 20,519
Blog Entries: 28

Rep: Reputation: 6573Reputation: 6573Reputation: 6573Reputation: 6573Reputation: 6573Reputation: 6573Reputation: 6573Reputation: 6573Reputation: 6573Reputation: 6573Reputation: 6573
There's lots of docs at the Nagios site.

http://www.nagios.org/documentation
 
Old 09-02-2011, 08:39 PM   #6
amachina
LQ Newbie
 
Registered: Aug 2006
Location: VA
Distribution: Fedora, Red Hat
Posts: 9

Rep: Reputation: 1
Code:
#!/bin/bash
#
# Name: chk_fs.sh
# Schedule: Every 20 minutes
# Function: Check all filesystems except /uxx; alert if used % exceeds PCT

PCT=85
typeset -a ARR
PVAL="/tmp/chkfs1.txt"
CVAL="/tmp/chkfs2.txt"
FSTYP=ext4
RECIPIENTS="user@host"

# gather current data
STRING=$(df -hPT | \
   grep ${FSTYP} | \
   awk '{print $2,$6,$7}' | \
   while read FSTYPE FSUSED FSNAME
   do
      if [[ "${FSNAME}" =~ "/u[0-9][0-9]" ]]
      then
         :
      else
         PCTUSD=$(echo ${FSUSED} | tr -d "%")
         if [[ ${PCTUSD} -ge ${PCT} ]]
         then
            echo "${FSNAME}:${FSTYPE}:${PCTUSD}"
         fi
      fi
   done)

# put current data in an array
((i=0))
for x in $(echo ${STRING})
do
   ARR[$i]=${x}
   ((i=i+1))
done
LENG=${#ARR[*]}

# check prior data against array
> ${CVAL}
if [[ ${LENG} -gt 0 ]]
then
   while read FSN USD REST
   do
      ((i=0))
      while [[ ${i} -lt ${LENG} ]]
      do
         CURFSN=$(echo ${ARR[$i]} | cut --delimiter=: --fields=1)
         CURUSD=$(echo ${ARR[$i]} | cut --delimiter=: --fields=3)
         if [[ "${FSN}" == "${CURFSN}" ]]
         then
            if [[ ${CURUSD} -ge ${USD} ]]
            then
               if [[ ${CURUSD} -gt ${USD} ]]
               then
                  echo -e "${FSN}\t\t${CURUSD}\t\t+" >> ${CVAL}
               else
                  echo -e "${FSN}\t\t${CURUSD}\t\t=" >> ${CVAL}
               fi
               ARR[$i]=0
            fi
         fi
         ((i=i+1))
      done
   done < ${PVAL}
fi

# check for new entries in array
((i=0))
while [[ ${i} -lt ${LENG} ]]
do
   if [[ "${ARR[$i]}" != "0" ]]
   then
      CURFSN=$(echo ${ARR[$i]} | cut --delimiter=: --fields=1)
      CURUSD=$(echo ${ARR[$i]} | cut --delimiter=: --fields=3)
      echo -e "${CURFSN}\t\t${CURUSD}\t\t!" >> ${CVAL}
   fi
   ((i=i+1))
done

cp ${CVAL} ${PVAL}

# send alert if necessary
FLAG=$(grep -c -e '+' -e '!' ${PVAL})
if [[ ${FLAG} -gt 0 ]]
then
   mailx -s "Filesystem Threshold Exceeded" $RECIPIENTS <<EOF
Date = $(date)
Host = $(hostname)
Threshold = ${PCT}%
Key: = no change; + increase; ! new entry

FileSystem  In Use         Change
==========  ======         ======
$(cat ${PVAL})
EOF
fi

Last edited by amachina; 09-02-2011 at 08:43 PM. Reason: Improve formatting
 
Old 09-03-2011, 09:37 AM   #7
rakesh kumar mall
LQ Newbie
 
Registered: Feb 2007
Posts: 1

Rep: Reputation: 0
Disk space alert

You must need to configure nagios. It's good for monitoring CPU , Memory, HDD etc.You can also set e-mail and msg alert in nagios.
 
Old 09-05-2011, 02:04 AM   #8
digital-infinity
LQ Newbie
 
Registered: Jun 2011
Location: Warsaw, Poland
Distribution: OpenSuSE 12.1
Posts: 21

Rep: Reputation: Disabled
As root write to the file /etc/cron.d/check_disk_space this:

Code:
0 8 * * 1-5 root /bin/df -k | sed -e 's/\%//g' | /bin/awk '{if (xx>0 && $5>90) print $1" "$5"\%"; xx++;}
This one line script will check daily at 8:00 whether any mounted file system usage exceeds 90%. It sends email if there is any such file system.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script for disk space alert cmontr Programming 6 02-09-2019 04:05 AM
OPENNMS -how can i get disk space alert & memory alert BY MAIL saravanakumar Linux - Server 11 05-30-2014 08:45 AM
opennms --memory alert & disk alert issue saravanakumar Linux - Server 4 07-19-2011 10:54 AM
LXer: Perl script to monitor disk space and send an email alert LXer Syndicated Linux News 1 02-23-2007 01:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:01 PM.

Contact Us - Advertising Info - Rules - Privacy - Donations - Contributing Member - LQ Sitemap - "Weather apps tell you it'll rain. Wyndo tells you when to go."
Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions