Monit: outil de surveillance des services locaux

Monit est un outil open-source, sous licence GNU, de surveillance des services locaux sous GNU/Linux.

La particularité de Monit par rapport à d’autres outils de surveillance comme, par exemple Nagios ou Zabbix, est de pouvoir redémarrer le service en défaut tout en envoyant un e-mail à l’administrateur. La visualisation de l’état des services est accéssible via l’interface web de Monit.


Sommaire:

  1. Pré-requis
  2. Installation de Monit
  3. Configuration de Monit
  4. Exemples de services
    1. SSHD
    2. Apache2
    3. Mysql / MariaDb
    4. ProFTPd
    5. PostFix
    6. Espace disque
    7. Plex
    8. Spamassassin
  5. Bonus: Apache reverse proxy

Pré-requis

Pour pouvoir avoir accès à l’interface web de Monit, il faut avoir un serveur web.

apt-get install apache2

Installation de Monit

apt-get install monit

Pour configurer Monit, il faut éditer le fichier /etc/monit/monitrc, ensuite ajouter des fichiers de configuration pour chaques services à surveiller dans le répertoire /etc/monit/conf.d/.

Configuration de Monit

nano /etc/monit/monitrc

Configuration du daemon Munit: 2 minutes d’intervales(configuration par défaut)

set daemon 120

Déclaration d’un serveur de messagerie pour délivrer les messages d’alertes:

set mailserver mail.server.tld

Pour être notifier par mail de toutes les alertes:

set alert sysadm@foo.bar

Pour personnaliser l’expéditeur du mail:

set mail-format { from: monit@foo.bar }

L’accès à l’interface web de Monit:

set httpd port 2812 and
allow admin:monit

Par défaut le login et mot de passe sont admin et monit, à changer.
Pour auoriser l’accès à l’interface web de Monit uniquement en local, dé-commenter:

use address localhost
allow localhost
Configuration des services à surveiller

Exemples de services:

sshd:

check process sshd with pidfile /run/sshd.pid
start program  "/etc/init.d/ssh start"
stop program  "/etc/init.d/ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

Apache2:

check process apache with pidfile /run/apache2/apache2.pid
group www-data
start program = "/etc/init.d/apache2 start"
stop program  = "/etc/init.d/apache2 stop"
if cpu > 60% for 2 cycles then alert
if cpu > 90% for 5 cycles then restart
if totalmem > 500 MB for 5 cycles then restart
if children > 250 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if 3 restarts within 5 cycles then timeout

MySql ou MariaDB:

check process mysql with pidfile /run/mysqld/mysqld.pid
group mysql
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed unix "/var/run/mysqld/mysqld.sock" then restart
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

ProFTPd:

check process proftpd with pidfile /run/proftpd.pid
start program = "/etc/init.d/proftpd start"
stop program  = "/etc/init.d/proftpd stop"
if failed port 21 protocol ftp then restart
if 5 restarts within 5 cycles then timeout

Postfix:

check process Postfix with pidfile /var/spool/postfix/pid/master.pid
   group postfix
   start program = "/etc/init.d/postfix start"
   stop  program = "/etc/init.d/postfix stop"
   if failed host 46.105.124.227 port 25 protocol smtp then restart
   if 5 restarts within 5 cycles then timeout
   depends on postfix_rc

check file postfix_rc with path /etc/init.d/postfix
   group postfix
   if failed checksum then unmonitor
   if failed permission 755 then unmonitor
   if failed uid root then unmonitor
   if failed gid root then unmonitor

Espace disque

check filesystem home with path /home
        if space usage > 70% then alert
		
check filesystem racine with path /
        if space usage > 70% then alert

Plex

check process plex with pidfile "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/plexmediaserver.pid"
start program = "/usr/sbin/service plexmediaserver start"
stop program  = "/usr/sbin/service plexmediaserver stop"
if failed port 32400 type tcp then restart
if 5 restarts within 5 cycles then timeout

SpamAssassin

check process Spamassassin with pidfile /var/run/spamd.pid
   group mail
   start program = "/etc/init.d/spamassassin start"
   stop  program = "/etc/init.d/spamassassin stop"
   if 5 restarts within 5 cycles then timeout
   if cpu usage > 99% for 5 cycles then alert
   if mem usage > 99% for 5 cycles then alert
   depends on spamd_bin
   depends on spamd_rc 

check file spamd_bin with path /usr/bin/spamassassin
   group mail
   if failed checksum then unmonitor
   if failed permission 755 then unmonitor
   if failed uid root then unmonitor
   if failed gid root then unmonitor

check file spamd_rc with path /etc/init.d/spamassassin
   group mail
   if failed checksum then unmonitor
   if failed permission 755 then unmonitor
   if failed uid root then unmonitor
   if failed gid root then unmonitor

Par défaut, du moins sous Debian, Monit est actif. Pour vérifier il faut éditer le fichier /etc/default/monit et avoir:

START=yes

Une fois la configuration terminée, il faut relancer Monit:

service monit restart

Pour contrôler la bonne syntax des fichers de configuration de Monit et des services associés:

monit -t

Se connecter à l’interface web de monit: http://IP_server:2812/

 

Bonus: Apache reverse proxy

<VirtualHost *:80>

ServerName monit.domain.tld
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://ip.ip.ip.ip:2812
ProxyPassReverse / http://ip.ip.ip.ip:2812

</VirtualHost>

 

Inspiré de : mo-linux.com/monit-outil-de-surveillance-des-services-locaux/

Écrire un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec une *

Quelle est le premier caractère du mot 7pe0rk ? :