How to Check services and restart using Monit

I have a monitoring service Zabbix which dies every few weeks, because it’s MySQL tables were locked for too long during a backup… Annoying! mostly because it’s then dead unnoticed for not just a few minutes. So, how do you monitor a monitoring service? Or simply… How do you restart any service that has just gone away in a simple way?

I recently came across monit. They state it’s up and running in just 15min. I got it faster.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Daemonize and check every 2mins.
set daemon  120

# Mail settings, in case you want to receive notifications
set mailserver relay.example.org
set mail-format { from: root@host1.example.org }
set alert admin@example.org

# The first check
check process zabbix_server with pidfile /var/run/zabbix/zabbix_server.pid
        start program = "/etc/init.d/zabbix-server start"
        stop program = "/etc/init.d/zabbix-server stop"
        group server

You can also monitor network availability, application availability, file permissions and system utilization… I think this tool is really great for a small network, though I don’t think it would scale that well. Just give it a try.