Setup linux host monitoring and self healing using Monit

Posted in Linux

Monitor all the usual stuff like processes, files, directories, disk space, etc. AND set up simple processes for restarting services or umounting partitions when they reach thresholds. The monit.conf syntax is very straight-forward. I like the way they haven’t added any useless complexity as just an attempt to make it look sophisticated. I currently use mrtg to monitor bandwidth utilization, cpu usage, and even disk space on a group of servers, and i’ve used cacti and nagios in the past, but monit is by far the easiest to get setup and running. Of the three, it’s definitely the quickest to setup with the least hassle. I gave up on nagios and all its plugins a long time ago, so maybe that project has been revamped, but I dont plan on trying it out again anytime soon.

Ok, this is going to be short…

Install monit

$ sudo yum install monit -y
…Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
–> Running transaction check
—> Package monit.x86_64 0:4.10.1-8.fc10 set to be updated
–> Finished Dependency Resolution
Dependencies Resolved

Installed:
monit.x86_64 0:4.10.1-8.fc10
Complete!

Here’s what got installed:

$ rpm -ql monit
/etc/logrotate.d/monit
/etc/monit.conf
/etc/monit.d
/etc/monit.d/logging
/etc/rc.d/init.d/monit
/usr/bin/monit
/usr/share/doc/monit-4.10.1
/usr/share/doc/monit-4.10.1/CHANGES.txt
/usr/share/doc/monit-4.10.1/CONTRIBUTORS
/usr/share/doc/monit-4.10.1/COPYING
/usr/share/doc/monit-4.10.1/FAQ.txt
/usr/share/doc/monit-4.10.1/LICENSE
/usr/share/doc/monit-4.10.1/PLATFORMS
/usr/share/doc/monit-4.10.1/README
/usr/share/doc/monit-4.10.1/README.DEVELOPER
/usr/share/doc/monit-4.10.1/README.SSL
/usr/share/doc/monit-4.10.1/STATUS
/usr/share/doc/monit-4.10.1/UPGRADE.txt
/usr/share/man/man1/monit.1.gz
/var/log/monit

Edit the config file
Set up whatever monitoring you want. It’s all explained in comments, and everything is commented out to start with, so it’s not nearly as complicated as anything such as apache’s httpd.conf for example!

$ sudo vi /etc/monit.conf
set daemon 120 # poll every 2 minutes
set logfile syslog # you can set this to a file if you want
set mailserver mymail.hostname.com # leave this out if you want
#
set httpd port 8888 and
use address localhost
allow admin:password
#
set eventqueue
basedir /mnt/nfs/monit_events # directory where events will be stored
slots 100 # optionally limit queue size
#
check system localhost
if loadavg (1min) > 4 then alert
if loadavg (5min) > 2 then alert
if memory usage > 80% then alert
if cpu usage (user) > 60% then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then alert
#
check file some.special.file with path /usr/local/bin/somedir
if failed checksum and
expect the sum a93b7a93fb7f3ccb79bf3793793321 then unmonitor
if failed permission 700 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
alert admin@mydomain.com on {
checksum, permission, uid, gid, unmonitor
} with the mail-format { subject: File Alarm! }
group server

filed under http://www.holyshnikes.com/p/network-server-monitoring/4472“>network server monitoring

And you get the point… there’s examples like these throughout the configuration file. If you want to monitor a bunch of remote machines but you don’t want to mess with cacti and its dependencies, a mysql backend, etc. then try the “m/monit” version 5-beta6 that’s still downloadable for free on http://www.tildeslash.com” alt=”monit server monitoring home page”>Monit’s site right now. They say its going to be licensed software after they close the beta “in february” but I was still able to download it just the other day.

There’s also a RPM spec file in the beta tarball so you can include your own custom configs and turn it into an rpm to make it even easier to install on a group of machines. I’m thinking about trying it out on a my test cluster at work…

Posted by admica   @   4 February 2009

Related Posts

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Fedora 10 Default Services
Next Post
Grep IP addresses from ifconfig »
Powered by Wordpress   |   Lunated designed by ZenVerse