Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a simple way of getting an email alert whenever the diskspace of a server gets above X % or has less than X Mb free.

I don't need anything too special, I don't need graphs or anything like that, just an email to let me know when my server is about to run out of space so I can run cleanup jobs. Right now I'm looking into setting up cleanup jobs with Jenkins, I just need something in the mean time to make sure the server keeps running.

This is for an Ubuntu server.

share|improve this question
    
It's pretty easy to write your own simple shell script involving df, and mailx commands with crontab to schedule them. –  mdpc Feb 12 '13 at 21:49

2 Answers 2

up vote 3 down vote accepted

I suggest you take a serious look at monit. It is a light weight local monitoring tool.

Your config for monitoring for the root filesystem would look as simple as this.

check filesystem rootfs with path /
    if space usage > 80% then alert

The global monit config would look about like this.

set daemon  180           # check services at 3-minute intervals
#     with start delay 240  # optional: delay the first check by 4-minutes
set logfile syslog facility log_daemon


set alert Stack_Admin_Rage@example.org
set mailserver mailserver.example.org
share|improve this answer

You could probably do the following in roots crontab:

10 * * * *      [ $(/bin/df --output=used /dev/diskid | /usr/bin/tail -1) -gt CHECKSIZE ] && /bin/mail -s "/dev/diskid Is to large" me@my.address

This command will basically automate checking the amount of used space, and if its bigger then CHECKSIZE will send you an email. It simply munges "df" to get the amount of disk used.

Realistically though, if you are going to be running multipler services/servers, you should look at Nagios - while it is a bit of a pain to set up, it is a great framework to check everything, all the time, with lots of free plugins. Most reputable companies would run it (or something equivalent)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.