Monitor Services On Ubuntu 12.04 With Monit

Overview

Monit is a very simple daemon which monitors conditions. Conditions can be defined as anything from a file to mounted drives. Monit can send email alerts, log to syslog and also restart services.

Install Mail Transfer Agent (MTA)

To enable email notification an smtp server must be available to send email alerts. This can be a hosted email service or one that resides on the computer. Installing one is beyond this guide but in the examples below it will use a local MTA.

Install Monit

sudo apt-get install monit

Configure Monit

By default the configuration file is an example configuration file and is located at /etc/monit/monitrc. Most of the directives are commented out and can be easily commented in and should work. Set the following items as a minimum:
set daemon 120
Poll interval to check the services.

set mailserver localhost
The mail server to send email notifications.

set alert root@domain.com
Set the email address to who should get alerts.

Below are examples of monitoring services and other features. Monit provides a very simple syntax which are fairly easy to read and understand:
## Check Apache2 is running
group server
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed host 127.0.0.1 port 80 then restart
if 5 restarts within 5 cycles then timeout

check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

Summary

Monit is a very simple monitoring service and as long as it has an internet connection then it will be able send very simple email alerts when a service goes down or restarts.

Monitoring Ubuntu Services Using Monit
Configuration Examples

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Linux and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *.

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.