Monit: Disk space monitoring

One thing you definitely don’t want to happen to your server is for it to run out of disk space, especially the root partition.

There are lots of pieces of open source monitoring software, a popular one being monit.

Below is a quick guide to installing monit and generating alert e-mails for disk space and cpu/memory usage. The installation was done on a SysAdminMan VPS running CentOS 5.5

First download and compile the software –

cd /usr/src
wget http://mmonit.com/monit/dist/monit-5.2.4.tar.gz
tar xvfz monit-5.2.4.tar.gz
cd monit-5.2.4
./configure
make
make install

If the ‘make’ fails you may need to install the following requirements –

yum install gcc flex

Next generate a configuration file. The alert thresholds should be fairly self explanatory, there are many more options –

cat >> /etc/monitrc <<-EOF
set daemon 300
with start delay 240
set logfile syslog facility log_daemon
set idfile /var/.monit.id
set statefile /var/.monit.state
set mailserver localhost
set alert [email protected]

check system localhost
if memory usage > 85% then alert
if cpu usage (user) > 80% for 3 cycles then alert
if cpu usage (system) > 80% for 3 cycles then alert

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

chmod 0700 /etc/monitrc

Next we are going to set the desired e-mail alert address. Don’t forget to change it to your e-mail address! –

sed -i 's/[email protected]/[email protected]/' /etc/monitrc

and now we just set monit to start when the system it restarted and fire it up –

echo "mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc" >> /etc/inittab
kill -HUP 1

A good idea is to temporarily set the disk space alert to something low (say 1%) and ensure that the monit alerts are working.

5 thoughts on “Monit: Disk space monitoring

  1. Pingback: Link: Monit: Disk space monitoring « The Michigan Telephone blog

  2. Serhiy

    Hi
    Thanks for great tutorial
    Just a quick question is there special implementation for Elastix and you getting alert at reboot only or when server working too as I’m getting only after reboot once.
    Thanks in advance

  3. matt Post author

    You should only get an alert if there is something wrong (or at start/stop). Did you try setting the threshhodld low temporarily to make it trip and send an e-mail?

  4. Serhiy

    Hi
    yes I have tried but alert only come at reboot not before that.
    For example I changed 75 to 10 as you advised and there was no alert until reboot. This is not normal any thing I can do to check why?

  5. gilbert.ginder

    hi
    u can use elastix addon space cleaner. it will be checking free space and remove files over setting quote

Comments are closed.