Disk Space Monitoring

5

3

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.

AlbertEngelB

Posted 2013-02-12T20:39:50.393

Reputation: 686

It's pretty easy to write your own simple shell script involving df, and mailx commands with crontab to schedule them. – mdpc – 2013-02-12T21:49:27.960

Answers

7

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

Zoredache

Posted 2013-02-12T20:39:50.393

Reputation: 18 453

1

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)

davidgo

Posted 2013-02-12T20:39:50.393

Reputation: 49 152