Monit: easily use triggers on your system

From Deimos.fr / Bloc Notes Informatique
Jump to: navigation, search
Monit

Software version 5.4-2
Operating System Debian 7
Website Monit Website
Last Update 28/05/2014
Others

1 Introduction

monit[1] 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.

2 Installation

To install Monit, this is simple:

Command
aptitude install monit

3 Configuration

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

Configuration File /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:

Configuration File /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[2].

3.1 Web interface

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

Configuration File /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.

4 References

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