Monit
Monit — это легковесная система мониторинга серверов, имеющая открытый исходный код. Monit устанавливается на сервер и обеспечивает возможность отправки уведомлений в случае обнаружения проблем. Кроме того, Monit может автономно выполнять определенное действие в качестве реакции на заданные события.
$ sudo yum install monit
Расскоментируем такие строки:
$ sudo nano /etc/monitrc set mailserver localhost set mail-format { from: monit@domen.com } set alert admin@domen.com set httpd port 2812 and use address localhost # only accept connection from localhost allow localhost # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit' include /etc/monit.d/*.conf
Проверяем синтаксис:
$ sudo monit -t
Запускаем:
$ sudo systemctl start monit $ sudo systemctl status monit $ sudo systemctl enable monit $ monit status
Создаем конфигурации мониторинга
cd /etc/monit.d/
$ sudo nano filesystem.conf check device root with path /dev/mapper/centos-home if space usage > 85% for 5 times within 15 cycles then alert if inode usage > 85% then alert check device home with path /dev/sdb if space usage > 85% for 5 times within 15 cycles then alert if inode usage > 85% then alert
$ sudo nano mariadb.conf # Monitor MariaDB check process mysql with pidfile /var/run/mariadb/mariadb.pid group database start program = "/usr/bin/systemctl start mariadb" stop program = "/usr/bin/systemctl stop mariadb" #if failed host 127.0.0.1 port 3306 then restart #if 5 restarts within 5 cycles then timeout
$ sudo nano system.conf check system host.domen.com if loadavg (1min) > 4 then alert if loadavg (5min) > 2 then alert if memory usage > 75% then alert if swap usage > 25% then alert if cpu usage (user) > 70% then alert if cpu usage (system) > 30% then alert if cpu usage (wait) > 20% then alert $ sudo nano nginx.conf check process nginx with pidfile /var/run/nginx.pid start program = "/usr/sbin/nginx start" stop program = "/usr/sbin/nginx stop"
$ sudo nano postfix.conf # Monitor postfix mailserver check process postfix with pidfile /var/spool/postfix/pid/master.pid group mail start program = "/usr/bin/systemctl start postfix" stop program = "/usr/bin/systemctl stop postfix" if failed port 25 protocol smtp then restart if 5 restarts within 5 cycles then timeout
$ sudo nano proftpd.conf # Monitor the Proftpd service check process proftpd with pidfile /var/run/proftpd/proftpd.pid start program = "/usr/bin/systemctl start proftpd" stop program = "/usr/bin/systemctl stop proftpd" #if failed port 21 protocol ftp then restart #if 5 restarts within 5 cycles then timeout