Monit is an opensource software for monitoring. Monit can monitor background processes, filesystems and file permissions as well as system devices. Monit has the ability to do these all tasks without taking too much CPU time or memory.
Note:- Text in bold letters denotes either a command or some configuration.
As I have installed FEDORA 10 from live CD, so minimum packages are installed. First of all install wget by.
#yum install wget
After installation of wget, download the source tar ball by.
Below are the decencies if you are trying to install via source tar ball.
- gcc (yum install gcc)
- flex (yum install flex)
- bison (yum install bison)
- openssl and openssl-devel (yum install openssl openssl-devel)
And you’re done with decencies.
As I am installing monit via yum so I do not need these dependencies, as yum will handle these by itself.
For yum based install just do the following.
#yum install monit
Source based install execute below three commands.
- make install
You are done with installation of monit.
The configuration file of monit in Fedora or RedHat is /etc/monit.conf and in debian based system /etc/monit/monitrc.
If you open this file all the lines in this files will be commented so we should enable only one directive here which includes /etc/monit.d/*
Then put all the configurations by creating another file on the path /etc/monit.d/.
We will create /etc/monit.d/monitconf/ and start configuration there.
Open the file and start configuring it.
1) set daemon 20
Set daemon directive tells monit, the interval to check daemon, files, directories etc. after. We set it to 20. So after 20 seconds it will check the daemons for monitoring. Default time is 120 seconds.
2) set logfile syslog
In this directive we are telling monit to log things to syslog.
3) set mailserver “smtp.gmail.com” port “587”
username email@example.com password “password”
with timeout 30 seconds
set alert firstname.lastname@example.org
In the above snippet we defined the email alerts. So, when a daemon or file or directory is not running or there is some permission problem it will send an email to email@example.com using SMTP from firstname.lastname@example.org after 30 seconds.
4) set httpd port 2812 and
use address localhost
Monit also has web features so you can enable it by the above code. Monit will listen for requests on port “2812” and will allow only localhost and 192.168.0.0/24.
So if someone writes web URL other then localhost:2812 and 192.168… it will be denied. You can access monit interface with username “toqi” and password “monit”.
Basic configuration of monit has been completed. Now you can add some extra configuration to monitor your specific services and system.
To check your configuration.
Access the web via http://localhost:2812, enter your username toqi and password monit.
For the sake of illustration, I will add some configuration to monitor system and httpd service.
Now add the following in your configuration file.
If loadavg (1min) > 4 then alert
If loadavg (5min) > 2 then alert
If memory usage > 75% then alert
If cpu usage (user) > 20% then alert
check process httpd with pidfile = /usr/tun/httpd.pid
start program = “/etc/init.d/httpd start”
stop program = “/etc/init.d/httpd stop”
if children > 250 then restart
if loadavg (5min) greater then 10 for 8 cycles then stop
if 3 restart without 5 cycles then timeout
Above snippets are self explained. These are all the conditions in which monit will send an alert to the administrator of the system. Now restart the service of monit via “service monit restart” and check with the webinterface you will get some info about http.
If you have any questions about monit please ask.