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.
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.
sudo apt-get install 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
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