Skip to content

Monit – Keeping Servers running even while asleep

One of the downsides to working on the internet, is that it never stops – it is a 24 hour a day, 365 day a year system. There is not ‘break’ in it, no time to rest.

When you run your own websites this can be a problem, a lot of people however get website hosting from a company as part of a package where they manage and monitor the servers for you.

If, like me, you run your own server, a dedicated monitoring service often costs extra to the hosting package. Now, some of us like our sleep, but also like to know our services are reliable, short of having someone awake 24 hours a day to monitor the servers you have to take chance that they will be reliable when you are away from an internet connected computer.

This is where monit comes in, it is a very useful package to allow a server to monitor itself for possible problems and restart / reset services if they start to run out of control.

Once installed, configuring monit is really straight forwards. Simply edit /etc/monit.conf and set up a few options pertaining to your server setup like mail server, and then how often you want to check services.

Once monit is configured, it is a case of setting up a collection of rules to tell monit how and what to scan.


check process httpd with pidfile /var/run/httpd.pid
group httpd
start program = "/etc/init.d/httpd start" with timeout 60 seconds
stop programĀ  = "/etc/init.d/httpd stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if failed host 127.0.0.1 port 80 protocol http for 5 cycles then restart
if 5 restarts within 5 cycles then timeout

In this example, I’m monitoring Apache via process ID, we tell monit how to start and stop apache then set a few rules on how to deal with it. In this case, if the Apache starts to eat more than 60% of my CPU for 2 runs through I send an alert email, if it stays above 80% for 5 runs then I restart it. If a connection test fails, restart too.

This allows me to make sure my server always responds and if it does get too heavily loaded then reset itself to reign the load in.

Using Monit allows me to spend time away from my servers without worrying that excess load or a software crash can take them down for too long. This doesn’t fix actual machine issues, but I just have to take the chance there.

Published inLinuxServers

Be First to Comment

Leave a Reply

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