Monitor and Manage your services with Monit on CentOS 6 / RHEL 6
Monit is an opensource process tool for Linux operating system which helps you to monitor system process using web browser and also when ever requires it automatically do the maintenance or repair of particular process in such a way that it can be brought back online. It can also used for managing and monitoring of programs, files, directories, and devices for timestamps changes, checksum changes, or size changes; not limited to perform various TCP/IP network checks, protocol checks, and can utilize SSL for such checks.
It logs to its own log file and notifies the user via customizable messages, this guide will help you to setup monit on CentOS / RHEL.
Configure EPEL repo to download the latest Monit package.
[[email protected] ~]# rpm -Uvh http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm
Install the Monit.
[[email protected] ~]# yum -y install monit
Start monit by using the following command.
[[email protected] ~]# monit
Check the monit status.
[[email protected] ~]# monit status
The Monit daemon 5.1.1 uptime: 0m
System 'server.itzgeek.com'
status running
monitoring status monitored
load average [0.12] [0.11] [0.09]
cpu 91.6%us 8.3%sy 0.0%wa
memory usage 727512 kB [71.8%]
data collected Mon Jul 7 07:51:09 2014
Configure Monit:
Monit conig file is /etc/monit.conf, by default monit is set to check the services at interval of 2 min, this setting can be altered by changing.
[[email protected] ~]# vi /etc/monit.conf
set daemon 120
Alert cans be configured by.
set mailserver
Alert templates can be found in the configuration file itself.
Logs setting can be changed by using the following file.
[[email protected] ~]# vi /etc/monit.d/logging
set logfile
Web Interface:
Monit also provides a web interface to monitor and manage the configured services, by default monit listens on 2812 port but it needs to be setup. Open monit configuration file /etc/monit.conf.
[[email protected] ~]# vi /etc/monit.conf
Look for httpd port 2812, uncomment the line.
set httpd port 2812
allow 0.0.0.0/0.0.0.0
allow admin:admin
From the above settings, monit will listen on 2812; admin user will able to access the web interface from any network.
Reload monit.
[[email protected] ~]# /etc/init.d/monit restart
Access the web interface by using http://your-ip-address:2812, use the username and password mentioned in the previous step. Monit home page will look like this.

Configuring services for monitoring:
Once the web interface is up, we can start to setup other services that you want to monitor; you can place the configuration files under /etc/monit.d/ directory.
Configure for sshd.
[[email protected] ~]# vi /etc/monit.d/sshdmonitor
check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/sshd start"
stop program "/etc/init.d/sshd stop"
if failed port 22 protocol ssh then restart
Configure for syslog.
[[email protected] ~]# vi /etc/monit.d/syslogmonitor
check process syslogd with pidfile /var/run/syslogd.pid
start program = "/etc/init.d/rsyslog start"
stop program = "/etc/init.d/rsyslog stop"
Once configured, test the monit syntax
[[email protected] ~]# monit -t
Control file syntax OK
Reload configuration fie to take effect of changes.
[[email protected] ~]# monit reload
Access the web interface, you would find the new services that we configured earlier.

Test the Monitoring:
Now stop the syslog daemon.
[[email protected] ~]# /etc/init.d/rsyslog stop
Wait for 30 second, monit will start the syslog automatically. You can find it in monit log.
[[email protected] ~]# cat /var/log/monit
[IST Jul 7 08:50:27] error : 'syslogd' process is not running
[IST Jul 7 08:50:27] info : 'syslogd' trying to restart
[IST Jul 7 08:50:27] info : 'syslogd' start: /etc/init.d/rsyslog
[IST Jul 7 08:51:28] info : 'syslogd' process is running with pid
That’s All, We have successfully configured Monit on CentOS 6 / RHEL 6. We welcome your feedback, please post your valuable comments below.