-
-
Notifications
You must be signed in to change notification settings - Fork 1
HOWTO devops monit
Install & configure Monit for checking MongoDB/web server status.
- see: D.O. tutorial on Monit
- see: Monit documentation
- the Monit embedded http server is needed especially if you want to issue monit commands from
the command line (it uses HTTP to talk to the demon): for instance, when lanunching:
$ monit status
or$ monit summary
Install vim
, if you haven't, in order to edit config files (otherwise, use the nano
editor):
$> sudo apt-get install vim
Install sendmail
or postfix
to send out email notifies on process events:
$> sudo apt-get install sendmail
Install monit
:
$> sudo apt-get install monit
Add monit to the startup scripts:
$> sudo update-rc.d monit defaults
To fine tune the configuration file and in order to setup any additional services that are in need of monitoring (any other web server, additional DB server, whatever...), use:
$> sudo vi /etc/monit/monitrc
See below for some configuration examples.
Some misc command examples.
$> monit
$> monit status
$> monit reload
$> monit quit
Configuration setup for resource monitoring:
----8<---- [> vi /etc/monit/monitrc
]
# [...]
check system localhost
group system
if memory usage > 85% then alert
if cpu usage (user) > 95% then alert
if cpu usage (system) > 50% then alert
# [...]
----8<----
Configuration setup for Apache2 monitoring:
----8<---- [> vi /etc/monit/monitrc
]
# [...]
check process apache2 with pidfile /run/apache2/apache2.pid
group server
start program = "/etc/init.d/apache2 restart" with timeout 30 seconds
stop program = "/etc/init.d/apache2 stop"
# [...]
----8<----
Configuration setup for NGinx monitoring:
----8<---- [> vi /etc/monit/monitrc
]
# [...]
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
# [...]
----8<----
Useful after each modify to the config file:
$> monit -t
$> monit start all
Taken directly from Goggles, legacy vers. 5:
----8<---- [> vi /etc/monit/monitrc
]
# [...]
set daemon 180 # check services at 2-minute intervals
with start delay 120 # optional: delay the first check by 2-minutes
# [...]
set logfile /var/log/monit.log
# [...]
set mailserver localhost
# [...]
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue size
# [...]
set mail-format { from: monit@<SITE_NAME.DOMAIN> }
# [...]
set alert webmaster@<SITE_NAME.DOMAIN> not on { instance, action }
# Local httpd server for status reporting:
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'
# [...]
check system localhost
group system
if memory usage > 85% then alert
if cpu usage (user) > 95% then alert
if cpu usage (system) > 50% then alert
# [...]
# [Steve, 20150521] Apache 2:
check process apache2 with pidfile /run/apache2/apache2.pid
group server
start program = "/etc/init.d/apache2 restart" with timeout 30 seconds
stop program = "/etc/init.d/apache2 stop"
# [...]
# [Steve, 20150521] MySql:
check process mysql with pidfile /run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql restart"
stop program = "/etc/init.d/mysql stop"
# [...]
----8<----
- On OpenSuse installations, AppArmor must not block MySql instances upon periodic check:see this