Home > IT-bullshit, System administration > mmonit: monitoring / response system

mmonit: monitoring / response system

mmonit – server monitoring system, able to perform at an event specified in the config scripts. For example, restart the service \ daemon when it drops or stops working, send notifications, run the daemon with a certain parameter and more.

Setup

Installation is simple. For FreeBSD:

# cd /usr/ports/*/monit

Add to autostart:

# echo 'proftpd_enable="YES"' >> /etc/rc.conf

For CentOS:

# yum install monit -y

Add to autostart:

# chkconfig monit on

Next, we have to set monitoring objects. For each service has own configuration, because different services are monitored in different ways. This can be checked by .pid-file approach to the url or checking port availability, type telnet commands, and more.

Configs for different services

Main file that describes the monitoring objects – it monitrc_local. Let’s divide it into two parts content: first part – mandatory, which must be everywhere, including our settings. The second part – according to the description of the service that you want to monitor. The first part of the config:

set daemon 120 with start delay 5 # time, after monit starts checking
set logfile /var/log/monit.log # log file
set mailserver mail.domain.com, localhost # your mail-server

set alert monit@domain.com # your admin mail. monit will send you notofications

set httpd port 2812 and # protocol and monit's web-interface
use address srv21.domain.local # server's hostname (use own one)
signature disable
allow localhost # allow localhost 🙂
allow 192.168.0.0/255.255.0.0 # allow acces from this subnetworks
allow @users # allow this @group
allow monit:monitadmin # allow user:password

Next, in this file below, you can find monitoring policies. For each servers they are different.

For Apache

We will see for Apache via .pid and page availability (url).
Config for this:

check process apache with pidfile /var/run/httpd.www.pid # check .pid-файл
group www # monitoring group 
start program = "/usr/local/etc/rc.d/apache22 start" with timeout 50 seconds # command for start cervice
stop program = "/usr/local/etc/rc.d/apache22 stop" with timeout 50 seconds # command for stop service
if failed host lst207.b.ls1.ru port 8000 # if url will not available /monit/token on port 8000 then
protocol HTTP request "/monit/token" with timeout 30 seconds then restart # restart service after 30 seconds

For nginx

Monitoring for nginx almost the same like for Apache. Difference only in service port.

check process nginx with pidfile /var/run/nginx.pid # check .pid-file
group www # monitoring group
start program = "/usr/local/etc/rc.d/nginx start" # command for start service
stop program = "/usr/local/etc/rc.d/nginx stop" # command for stop service
if failed host lst207.b.ls1.ru port 80 # if url will not available /monit/token on port 8000 then
protocol HTTP request "/monit/token" with timeout 20 seconds then restart # restart service 30 second

For redis

redis monitored much more interesting than the web server: it comes to telnet on redis port, enters commands and expects definite answer. If the answer is yes, monit does not perform any action. If the answer is no, monit will restart redis. Here is config file:

 

check process redis.service match "redis-server" # looking for processes with name
group db # monitoring group
start program = "/usr/local/etc/rc.d/redis start" with timeout 50 seconds # command for start service
stop program = "/usr/local/etc/rc.d/redis stop" with timeout 50 seconds # command for stop service
if failed
port 6379 # port redis
send "SET MONIT-CHECK ok\r\n" # send message
expect "OK" # wait for answer
send "EXISTS MONIT-CHECK\r\n" # send message
expect ":1" # wait for answer
then restart # restart
if 5 restarts within 5 cycles then timeout # timeout after 5 restarts and 5 cycles

For Gearman

check process gearmand with pidfile /var/run/gearmand/gearmand.pid
group gearmand
start program = "/usr/local/etc/rc.d/gearmand start"
stop program = "/usr/local/etc/rc.d/gearmand stop"
if failed host 127.0.0.1 port 4730 then restart
if 5 restart within 5 cycles then timeout
Categories: IT-bullshit, System administration Tags:
  1. No comments yet.
  1. No trackbacks yet.