1. cd /usr/ports/sysutils/monit
2. make install clean
3. cp /usr/local/etc/monitrc.sample /usr/local/etc/monitrc
4.В /etc/rc.conf добавить monit_enable=”YES”
5.Файл /usr/local/etc/monitrc привести к виду:
set daemon 60 # частота(интервал)проверки сервисов
set logfile /var/log/monit.log # записывать логии в отдельный файл /var/log/monit.log
set idfile /var/.monit.id
set statefile /var/.monit.state
set mailserver localhost # IP/hostname почтового сервера,через который будут отправляться сообщения
set eventqueue # разрешить очередь сообщения
basedir /var/monit # путь к каталогу,где будут храниться уведомления
slots 100 # максимальное количество сообщений в очереди
## Monit by default uses the following format for alerts if the the mail-format
## statement is missing::
## —8<—
## set mail-format {
## from: monit@$HOST
## subject: monit alert — $EVENT $SERVICE
## message: $EVENT Service $SERVICE
## Date: $DATE
## Action: $ACTION
## Host: $HOST
## Description: $DESCRIPTION
##
## Your faithful employee,
## Monit
## }
## —8<—
##
set alert root@localhost # Ящик для всех уведомлений
set httpd port 2812 and # порт,накотором запускается Web-интерфейс monit
use address 192.168.1.41 # принимать соединения на интерфейсе 192.168.1.41
allow 192.168.1.0/24 # разрешить сети 192.168.1.0/24 соединяться с сервером и localhost
allow localhost
allow admin:kamaok # требовать логин ‘admin’ и пароль ‘kamaok’
check system freebsd9.kamaok.org.ua
if loadavg (1min) > 6 then alert
if loadavg (5min) > 3 then alert
if memory usage > 75% then alert
if swap usage > 70% then alert
if cpu usage (user) > 70% then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then aler
include /usr/local/etc/monit.d/* # подключаем папку для описания проверки служб
6.Создать
а)файл /var/log/monit.log
б) папку /usr/local/etc/monit.d
в)файл /usr/local/etc/monit.d/services.conf с таким содержанием
г) в корне сайта kamaok.org.ua создаем файл с именем monit_apache с любым содержанием
cat /usr/local/etc/monit.d/services.conf(простой вариант с мониторингом одного локального хоста)
check process ntpd with pidfile /var/run/ntpd.pid
start program = «/etc/rc.d/ntpd start»
stop program = «/etc/rc.d/ntpd stop»
if failed host 127.0.0.1 port 123 type udp then restart
if 5 restarts within 5 cycles then timeout
check process ftpd with pidfile /var/run/ftpd.pid
start program = «/etc/rc.d/ftpd start»
stop program = «/etc/rc.d/ftpd stop»
if failed port 21 protocol ftp then restart
if 5 restarts within 5 cycles then timeout
check process sshd with pidfile /var/run/sshd.pid
start program «/etc/rc.d/sshd start»
stop program «/etc/rc.d/sshd stop»
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
check process named with pidfile /var/named/var/run/named/pid
start program = «/etc/rc.d/named start»
stop program = «/etc/rc.d/named stop»
if failed host 127.0.0.1 port 53 type tcp protocol dns then restart
if failed host 127.0.0.1 port 53 type udp protocol dns then restart
if 5 restarts within 5 cycles then timeout
check process snmpd with pidfile /var/run/net_snmpd.pid
start program = «/usr/local/etc/rc.d/snmpd start»
stop program = «/usr/local/etc/rc.d/snmpd stop»
if failed host 192.168.1.41 port 161 type udp then restart
if failed host 192.168.1.41 port 199 type tcp then restart
if 5 restarts within 5 cycles then timeout
check process mysql with pidfile /var/db/mysql/freebsd9.kamaok.org.ua.pid
# group database
start program = «/usr/local/etc/rc.d/mysql-server start»
stop program = «/usr/local/etc/rc.d/mysql-server stop»
if failed host 192.168.1.41 port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout
check process httpd with pidfile /var/run/httpd.pid
# group www
start program = «/usr/local/etc/rc.d/apache22 start»
stop program = «/usr/local/etc/rc.d/apache22 stop»
if failed host kamaok.org.ua port 80 protocol HTTP
request «/monit_apache» then restart
if 5 restarts within 5 cycles then timeout
check process memcached with pidfile /var/run/memcached/memcached.pid
start program = «/usr/local/etc/rc.d/memcached start»
stop program = «/usr/local/etc/rc.d/memcached stop»
if failed host 192.168.1.41 port 11211 then restart
if 5 restarts within 5 cycles then timeout
Либо более расширенный вариант(с мониторингом удаленных хостов)
cat /usr/local/etc/monit.d/service.conf
check host freebsd9 with address kamaok.org.ua
if failed icmp type echo count 5 with timeout 10 seconds then alert
check host evgen_homePC with address 192.168.1.11
if failed icmp type echo count 5 with timeout 10 seconds then alert
check host evgen_notebook with address 192.168.1.4
if failed icmp type echo count 5 with timeout 10 seconds then alert
check host mygentoo4 with address 192.168.1.34
if failed icmp type echo count 5 with timeout 10 seconds then alert
if failed port 22 protocol ssh then alert
if failed port 161 type udp then alert
if failed port 3306 protocol mysql then alert
if failed port 80 protocol HTTP then alert
if failed port 11211 then alert
alert root@localhost
check process ntpd with pidfile /var/run/ntpd.pid
start program = «/etc/rc.d/ntpd start»
stop program = «/etc/rc.d/ntpd stop»
if failed host 127.0.0.1 port 123 type udp then restart
if 5 restarts within 5 cycles then timeout
check process ftpd with pidfile /var/run/ftpd.pid
start program = «/etc/rc.d/ftpd start»
stop program = «/etc/rc.d/ftpd stop»
if failed port 21 protocol ftp then restart
if 5 restarts within 5 cycles then timeout
check process sshd with pidfile /var/run/sshd.pid
start program «/etc/rc.d/sshd start»
stop program «/etc/rc.d/sshd stop»
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
check process named with pidfile /var/named/var/run/named/pid
start program = «/etc/rc.d/named start»
stop program = «/etc/rc.d/named stop»
if failed host 127.0.0.1 port 53 type tcp protocol dns then restart
if failed host 127.0.0.1 port 53 type udp protocol dns then restart
if 5 restarts within 5 cycles then timeout
check process snmpd with pidfile /var/run/net_snmpd.pid
start program = «/usr/local/etc/rc.d/snmpd start»
stop program = «/usr/local/etc/rc.d/snmpd stop»
if failed host 192.168.1.41 port 161 type udp then restart
if failed host 192.168.1.41 port 199 type tcp then restart
if 5 restarts within 5 cycles then timeout
check process mysql with pidfile /var/db/mysql/freebsd9.kamaok.org.ua.pid
# group database
start program = «/usr/local/etc/rc.d/mysql-server start»
stop program = «/usr/local/etc/rc.d/mysql-server stop»
if failed host 192.168.1.41 port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout
check process httpd with pidfile /var/run/httpd.pid
# group www
start program = «/usr/local/etc/rc.d/apache22 start»
stop program = «/usr/local/etc/rc.d/apache22 stop»
if failed host kamaok.org.ua port 80 protocol HTTP request «/monit_apache» then restart
if failed host redmine.kamaok.org.ua port 80 protocol HTTP then alert
if failed host joomla.kamaok.org.ua port 80 protocol HTTP request «/monit_apache» then alert
if failed host wordpress.kamaok.org.ua port 80 protocol HTTP request «/monit_apache» then alert
if failed host domain1.com port 80 protocol HTTP request «/monit_apache» then alert
if 5 restart within 5 cycles then timeout
check process memcached with pidfile /var/run/memcached/memcached.pid
start program = «/usr/local/etc/rc.d/memcached start»
stop program = «/usr/local/etc/rc.d/memcached stop»
if failed host 192.168.1.41 port 11211 then restart
if 5 restarts within 5 cycles then timeout
freebsd9#
7. /usr/local/etc/rc.d/monit start
8.Web-интерфейс monit доступ на порту 2812
(Login: admin,Password:kamaok(согласно настройкам в monitrc)
9.Проверка синтаксиса monitrc
monit -t
10. Логи смотрим в /var/log/monit.log
Источники:
http://mmonit.com/wiki/Monit/ConfigurationExamples
http://mmonit.com/monit/documentation/monit.html
http://itbuben.org/blog/Unix-way/2450.html