wiki'd

by JoKeru

Server & Services monitoring with Monit

[cc lang='bash']
\$ apt-get install monit
\$ vi /etc/default/monit
\$ vi /etc/monit/monitrc
\$ /etc/init.d/monit start
[/cc]

/etc/monit/monitrc
[cc lang='bash']
set daemon 60 # check services at 1 minute intervals
set logfile syslog facility log_daemon # log to /var/log/daemon.log
set mailserver localhost port 25 # send alert mails using this server
set eventqueue # keep alert mails if mail server unavailable
basedir /var/monit
slots 100
set alert monit@jokeru.ro # send alert mails to this address
set httpd port 2812 and # start monit web server on this port
use address 10.20.30.40 # listen on this ip address
allow 50.60.70.80 # allow only this ip to connect
allow admin:monit # allow only this user/pass to connect

## SSH
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
host 10.20.30.40
port 22
type tcp
protocol ssh
then restart
#if 2 restarts within 2 cycles then timeout

## SNMP
check process snmpd with pidfile "/var/run/snmpd.pid"
start program = "/etc/init.d/snmpd start"
stop program = "/etc/init.d/snmpd stop"
if failed
host 127.0.0.1
port 161
type udp
then restart
#if 2 restarts within 2 cycles then timeout

## BIND
check process bind with pidfile "/var/run/bind/run/named.pid"
start program = "/etc/init.d/bind9 start"
stop program = "/etc/init.d/bind9 stop"
if failed
host 10.20.30.40
port 53
type tcp
protocol dns
then restart
if failed
host 10.20.30.40
port 53
type udp
protocol dns
then restart
#if 2 restarts within 2 cycles then timeout

## Apache
check process apache with pidfile "/var/run/apache2.pid"
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed
host 10.20.30.40
port 80
use type tcp
protocol http
for 2 times within 2 cycles
then restart
# then alert
if totalmem > 80% then alert
#if children = 200 then restart
#if 2 restarts within 2 cycles then timeout

## MySQL
check process mysql with pidfile "/var/lib/mysql/jokeru.pid"
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed
host 127.0.0.1
port 3306
type tcp
protocol mysql
for 2 times within 2 cycles
then restart
if cpu > 50% then alert
if totalmem > 25% then alert
#if 2 restarts within 2 cycles then timeout

## Postfix
check process postfix with pidfile "/var/spool/postfix/pid/master.pid"
start program = "/etc/init.d/postfix start"
stop program = "/etc/init.d/postfix stop"
if failed
host 10.20.30.40
port 25
type tcp
protocol smtp
with timeout 15 seconds
for 2 times within 2 cycles
then restart
#if 2 restarts within 4 cycles then timeout

## DK-Filter
check process dk-filter with pidfile "/var/run/dk-filter/dk-filter.pid"
start program = "/etc/init.d/dk-filter start"
stop program = "/etc/init.d/dk-filter stop"
if failed
host 127.0.0.1
port 8891
type tcp
then restart
#if 2 restarts within 2 cycles then timeout

## DKIM-Filter
check process dkim-filter with pidfile "/var/run/dkim-filter/dkim-filter.pid"
start program = "/etc/init.d/dkim-filter start"
stop program = "/etc/init.d/dkim-filter stop"
if failed
host 127.0.0.1
port 8892
type tcp
then restart
#if 2 restarts within 2 cycles then timeout

## Courier POP3
check process pop3 with pidfile "/var/run/courier/pop3d.pid"
start program = "/etc/init.d/courier-pop start"
stop program = "/etc/init.d/courier-pop stop"
if failed
host 10.20.30.40
port 110
type tcp
then restart
#if 2 restarts within 2 cycles then timeout

## Courier POP3-SSL
check process pop3-ssl with pidfile "/var/run/courier/pop3d-ssl.pid"
start program = "/etc/init.d/courier-pop-ssl start"
stop program = "/etc/init.d/courier-pop-ssl stop"
if failed
host 10.20.30.40
port 995
type tcp
then restart
#if 2 restarts within 2 cycles then timeout

## Pure-FTPd
check process pure-ftpd with pidfile "/var/run/pure-ftpd/pure-ftpd.pid"
start program = "/etc/init.d/pure-ftpd start"
stop program = "/etc/init.d/pure-ftpd stop"
if failed
host 10.20.30.40
port 21
type tcp
protocol ftp
then restart
#if 2 restarts within 2 cycles then timeout
[/cc]

Comments