Auf der Suche nach einer Software zur Überwachung von Serverdiensten auf meinem vServer bin ich auf Monit gestoßen. Monit ist ein leichtgewichtiges OpenSource Tool zur Überwachung von Serverdiensten und Dateien.
Da sich das Tool bereits im Debian Repository befindet kann es einfach mittels aptitude oder apt-get installiert werden.
aptitude install monit
Anschließend können diverse Einstellungen in der Datei ‘/etc/monit/monitrc’ durchgeführt werden.
#Alle 2 Minuten die konfigurierten Services überprüfen
set daemon 120
#HTTP Seite für Benutzer der Gruppe markus auf Port 2812 bereitstellen
set httpd port 2812 and allow @markus
#Alarme an webmaster [at] backes-markus [dot] de senden
set alert webmaster [at] backes-markus [dot] de
#Alle Konfigurationsdateien unter ‘/etc/monit/conf.d/*’ einbinden
include /etc/monit/conf.d/*
Das Einbinden eines Ordners mit Konfigurationsdateien dient zur besseren Wartbarkeit. In diesem Ordner können nun für alle zu überwachenden Programme einzelne Konfigurationsdateien angelegt werden.
Nun gibt’s einige Configs für den ‘/etc/monit/conf.d/’ Ordner:
Apache2
#/etc/monit/conf.d/apache2
check process apache2 with pidfile /var/run/apache2.pid
#Below is actions taken by monit when service got stuck.
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
# Admin will notify by mail if below of the condition satisfied.
if cpu is greater than 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 400.0 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
group server
Dovecot
#/etc/monit/conf.d/dovecot
check process dovecot with pidfile /var/run/dovecot/master.pid
start program = "/etc/init.d/dovecot start"
stop program = "/etc/init.d/dovecot stop"
group mail
if failed host backes-markus.de port 993 type tcpssl sslauto protocol imap for 5 cycles then restart
if 3 restarts within 5 cycles then timeout
depends dovecot_init
depends dovecot_bin
check file dovecot_init with path /etc/init.d/dovecot
group mail
check file dovecot_bin with path /usr/sbin/dovecot
group mail
MySQL
#/etc/monit/conf.d/mysqld
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host localhost port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout
depends on mysql_bin
depends on mysql_rc
check file mysql_bin with path /usr/sbin/mysqld
group database
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 mysql_rc with path /etc/init.d/mysql
group database
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
Postfix
#/etc/monit/conf.d/postfix
check process postfix with pidfile /var/spool/postfix/pid/master.pid
group mail
start program = "/etc/init.d/postfix start"
stop program = "/etc/init.d/postfix stop"
if failed 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 mail
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
Proftpd
#/etc/monit/conf.d/proftpd
check process proftpd with pidfile /var/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
sshd
#/etc/monit/conf.d/sshd
check process sshd with pidfile /var/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
Quellen: