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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-02-2011, 12:36 PM
|
#1
|
|
Member
Registered: Mar 2010
Posts: 61
Rep:
|
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.
|
|
|
|
09-02-2011, 12:46 PM
|
#2
|
|
Member
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172
Rep:
|
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.
|
09-02-2011, 01:52 PM
|
#3
|
|
Member
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770
Rep:
|
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.
|
|
|
|
09-02-2011, 04:22 PM
|
#4
|
|
Member
Registered: Mar 2010
Posts: 61
Original Poster
Rep:
|
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
|
|
|
|
09-02-2011, 07:42 PM
|
#5
|
|
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
|
There's lots of docs at the Nagios site.
http://www.nagios.org/documentation
|
|
|
|
09-02-2011, 08:39 PM
|
#6
|
|
LQ Newbie
Registered: Aug 2006
Location: VA
Distribution: Fedora, Red Hat
Posts: 9
Rep:
|
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
|
|
|
|
09-03-2011, 09:37 AM
|
#7
|
|
LQ Newbie
Registered: Feb 2007
Posts: 1
Rep:
|
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.
|
|
|
|
09-05-2011, 02:04 AM
|
#8
|
|
LQ Newbie
Registered: Jun 2011
Location: Warsaw, Poland
Distribution: OpenSuSE 12.1
Posts: 21
Rep: 
|
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.
|
|
|
|
All times are GMT -5. The time now is 05:01 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|