Monday, March 12, 2012

Monitor Your System Using Monit

Even a perfect system might have some glitches during normal operations. Human intervention is still required to perform several operations such as restarting a service, until Monit arrvices.

Monit eases sysadmin's job by checking the resources, processes, files, connections, and many other that you have defined in the monit configuration file and perform actions whenever they see any problems.

This is an example of how we monitored HTTPD Server (apache in this case) on Slackware machine:
set daemon 5
set logfile syslog facility log_daemon
check process httpd with pidfile /var/run/httpd/httpd.pid
start program = "/etc/rc.d/rc.httpd start"
stop program = "/etc/rc.d/rc.httpd stop"

set httpd port 8888
allow user:password

Add above lines in /root/.monitrc. Please make sure that the configuration only accessible to you, so give this command : chmod 700 .monitrc to set the permission.

Start monit using monit -d 5 (5 is the interval for checking and -d is for background/daemon mode) and you can start looking at your machine's HTTPD status by going through http://www.domain.com:8888 and login using user and password you defined in the configuration file.

You should also add the above command (monit -d 5) into /etc/rc.d/rc.local to make sure that monit will be executed everytime your machine had to reboot.

Basically, Monit can do more than just process checking. Read the documentation to find out more information about this cool application and what you can do with it.