Using email alerts with Monit

What is Monit? Let’s refresh our knowledge a little bit.

From Monit’s website:

Monit is a small Open Source utility for managing and monitoring Unix systems. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.


Adding email alerts

You can find additional posts about Monit on my website, and today we’re going to add email based alerts.

Let’s say we have Redis configuration for Monit:

check process redis-server with pidfile "/var/run/redis/"
    start program = "/etc/init.d/redis-server start"
    stop program = "/etc/init.d/redis-server stop"
    if failed host port 6379 then restart
    if 5 restarts within 5 cycles then timeout

Let’s add configuration section first into /etc/monit/monitrc:

set mail-format {
  subject: monit alert --  $EVENT
  message: $EVENT Service $SERVICE
                Date:        $DATE
                Action:      $ACTION
                Host:        $HOST
                Description: $DESCRIPTION

           Monit }
set mailserver port 587
  username XXX password "XXX"
  using TLSV1 with timeout 30 seconds
set alert

And simple restart Monit with:

sudo /etc/init.d/monit restart


Example email with Monit service monitoring alert: