Monitor Debian server with monit
Monit is a system monitoring utility which allows an admin to easily monitor files, processes, directories, or devices on your Debian system. It can also be used for automatic maintenance/repairs – by executing particular commands when errors arise. To ease of administration monit provide a web based monitoring interface, with SSL support. To install monit in to your Debian server, Simply use apt-get:
#apt-get install monit
Once installed, you’ll find the main configuration file located at /etc/monit/monitrc. Below is sample global configuration file, which will also explain some keywords. for more information do man monit
# poll at 2-minute intervals. Monit will wakeup every two minute to
# monitor things. Time must be given in seconds.
set daemon 120
#If port 25 broken for primary SMTP server,
#all alerts will redirect to secondary SMTP server or
#localhost after 15 seconds timeout.
set mailserver mail.bar.com, mail.foo.com port 10025,
localhost with timeout 15 seconds
# You can define your mail-notification format. Do man monit
mail-format {
from: foo@bar.com
subject: $SERVICE $EVENT at $DATE
message: Monit $ACTION $SERVICE at $DATE on $HOST,
Yours sincerely,
Foo Bar.
}
# Make monit start its web-server. So you can access it from webrowser.
set httpd port 2812 and
use address 192.168.0.1 # or bar.com
##Monit web-server ACL.
allow localhost # allow localhost to connect to the server and
allow 192.168.1.2 # allow 192.168.1.2 to connect to the server,
# You can give only one entry per line.
allow foo:bar # user name and password for authentication.
allow bar:bar # set multiple user to access through browser.
Below is some of the checks that can monitor the various services on the server.
check process apache with pidfile /var/run/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed host 127.0.0.1 port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout
check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/ssh start"
stop program "/etc/init.d/ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
check process named with pidfile /var/run/named.pid
start program = "/etc/init.d/bind start"
stop program = "/etc/init.d/bind stop"
if failed host 127.0.0.1 port 53 type tcp then alert
if failed host 127.0.0.1 port 53 type udp then alert
if 5 restarts within 5 cycles then timeout
check process exim4 with pidfile /var/run/exim4/exim.pid
start program = "/etc/init.d/exim4 start"
stop program = "/etc/init.d/exim4 stop"
if failed host 127.0.0.1 port 25 protocol smtp then alert
if 5 restarts within 5 cycles then timeout
check process clamavd with pidfile /var/run/clamav/clamd.pid
start program = "/etc/init.d/clamav-daemon start"
stop program = "/etc/init.d/clamav-daemon stop"
if failed unixsocket /var/run/clamav/clamd.ctl then restart
if 5 restarts within 5 cycles then timeout
You can also include other configuration files via include directives:
include /etc/monit/default.monitrc include /etc/monit/mysql.monitrc
After modifying the configuration file you should check for the syntax to make sure they are correct. To do this run:
# monit -t
Now you can run monit directly:
# monit
Once monit is running you can check for activity with your web-browser. You can of course use the Debian init script to start the monitoring:
/etc/init.d/monit start
For this to work you must enable the service by changing the file /etc/default/monit:
# You must set this variable to for monit to start startup=1 # To change the intervals which monit should run uncomment # and change this variable. # CHECK_INTERVALS=180
For more example of monit check the monit homepage.

Trackbacks and Pingbacks