Monit

Software version5.4-2
Operating SystemDebian 7
WebsiteMonit Website
Last Update28/05/2014

Introduction

Monit is a utility for managing and monitoring processes, programs, files, directories and filesystems on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. Monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses too much resources. You can use Monit to monitor files, directories and filesystems for changes, such as timestamps changes, checksum changes or size changes.

Monit is controlled via an easy to configure control file based on a free-format, token-oriented syntax. Monit logs to syslog or to its own log file and notifies you about error conditions via customizable alert messages. Monit can perform various TCP/IP network checks, protocol checks and can utilize SSL for such checks. Monit provides a http(s) interface and you may use a browser to access the Monit program.

Installation

To install Monit, this is simple:

  aptitude install monit
  

Configuration

Regarding the configuration file, you’ve got a global configuration file where you can adjust some parameters:

(/etc/monit/monitrc)

  set daemon 120            # check services at 2-minute intervals
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set mailserver localhost
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
slots 100                     # optionally limit the queue size
set alert my@email.com
set httpd port 2812 and
allow localhost        # allow localhost to connect to the server and
include /etc/monit/conf.d/*
  

But here is a configuration file to restart multiple services in a shell script when an URL is not containing a specific content:

(/etc/monit/conf.d/web)

  check host blog.deimos.fr with address blog.deimos.fr
    if failed (url http://blog.deimos.fr and content == 'Because human memory can not contain Gb')
    with timeout 20 seconds for 3 cycles
    then exec "/etc/scripts/web_services.sh restart"
    alert my@email.com
  

There are several type of usages with Monit and you can see examples here.

Web interface

Regarding the web interface, you can use Nginx and do a proxy pass to access from outside with credentials:

(/etc/nginx/sites-enabled/default)

      # Monit status
    location /monit/ {
        rewrite ^/monit/(.*) /$1 break;
        proxy_ignore_client_abort on;
        proxy_pass   http://127.0.0.1:2812; 
        # User access
        auth_basic "Please logon"; 
        auth_basic_user_file /etc/nginx/access/htaccess;
    }
  

And create the htaccess file with credentials.

References

  1. https://mmonit.com/monit/documentation/monit.html
  2. https://mmonit.com/monit/documentation/monit.html#configuration_examples

Last updated 28 May 2014, 09:11 CEST. history