Formatting code for MonitoringMonit


show source only

{{parent page="Monitoring"}}

===Monitoring with monit===

==Getting and installing monit==
Get it from http://tildeslash.com/monit/download/
Do a typical source install, then move forward to the next section

==Configuring monit to start in inittab==
First, create a monitrc file in /etc/monitrc. The following rc file monitors apache.

%%
set daemon 120 # Poll at 2-minute intervals
set logfile syslog facility log_daemon
set alert root@localhost
set httpd port 2812 and use address localhost
allow localhost # Allow localhost to connect
allow admin:monit # Allow Basic Auth

check process apache with pidfile /var/run/httpd.pid
group www
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80
protocol HTTP request / then restart
if totalmem > 90% for 2 cycles then restart
if loadavg(5min) > 20 for 2 cycles then restart
if 5 restarts within 5 cycles then timeout
depends on apache_bin
depends on apache_rc

check file apache_bin with path /usr/sbin/httpd
group www
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor

check file apache_rc with path /etc/init.d/httpd
group www
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
%%

chmod 600 /etc/monitrc, then add the following to inittab:

%%
# Run monit in standard run-levels
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc
%%

Restart the linux init process

%%
kill -HUP 1
%%

===Restart apache with monit===
This could be useful if apache (or most likely crappy php code) is not cleaning up

%%
check process apache
with pidfile "/usr/local/apache/logs/httpd.pid"
start program = "/etc/init.d/httpd start" with timeout 60 seconds
stop program = "/etc/init.d/httpd stop"
if 2 restarts within 3 cycles then timeout
if totalmem > 100 Mb then alert
if children > 255 for 5 cycles then stop
if cpu usage > 95% for 3 cycles then restart
if failed port 80 protocol http then restart
group server
depends on httpd.conf, httpd.bin
%%

====Note====
Sometimes monit acts weird, like when it starts it doesn't start up all services. Or it starts and certain service are started in not monitored state. I haven't figured out that yet but running **monit validate all** and **monit monitor all** seems to be helpful in those situations.

Ref: http://mmonit.com/monit/documentation/monit.html#examples
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki