Monitor Apache using monit

Monit is a small Open Source utility for managing and monitoring Unix systems. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.

Installing monit on CentOS 7


yum install epel-release -y
yum install monit -y

Once installed, save the following in /etc/monit.d/apache


check process httpd with pidfile /var/run/httpd/httpd.pid
group apache
start program = "systemctl start apache"
stop program = "systemctl stop apache"
if failed host 127.0.0.1 port 80 protocol http
with timeout 15 seconds
then restart
if 5 restarts within 5 cycles then timeout

Notes:

  1. Adjust httpd.pid if your apache’s pid is in a different location. On a default installation it might be at /var/run/httpd.pid

Start monit


# Checks for syntax errors
monit -t  
monit 

There are advanced settings which can be adjusted by modifying the file /etc/monitrc such as email notification etc.

Leave a Reply

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