Monitor Debian servers with monit

Posted by hardik on Mon 10 Oct 2005 at 12:01

Tags: ,

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 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 my sample configuration file, which will also explain some keywords.

set daemon  120
# poll at 2-minute intervals. Monit will wakeup every two minute to
# monitor things. Time must be given in seconds.

set logfile syslog facility log_daemon
# Set syslog logging.

# Set a default mail from-address for all alert messages emitted by monit.
# All alert mail will be sent to below mail address.
set mail-format { from: hardik@test.com }
set alert root@test.com

# You can define your mail-notification format. Do man monit 
mail-format {
    from: hardik@test.com
    subject: $SERVICE $EVENT at $DATE
    message: Monit $ACTION $SERVICE at $DATE on $HOST,

    Yours sincerely,
    Hardik Dalwadi.
    }

# Make monit start its web-server. So you can acccess it from webrowser.
set httpd port 2812 and
use address test.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 per entry

allow admin:monit # user name and password for authentication.
allow hardik:hardik # set multiple user to access through browser.

# Monitoring the apache2 web services.
# It will check process apache2 with given pid file.
# If process name or pidfile path is wrong then monit will 
# give the error of failed. tough apache2 is running.
check process apache2 with pidfile /var/run/apache2.pid

  #Below is actions taken by monit when service got stuck.
  start program = "/etc/init.d/apache2 start"
  stop program  = "/etc/init.d/apache2 stop"
  # Admin will notify by mail if below of the condition satisfied.
  if cpu is greater than 60% for 2 cycles then alert
  if cpu > 80% for 5 cycles then restart
  if totalmem > 200.0 MB for 5 cycles then restart
  if children > 250 then restart
  if loadavg(5min) greater than 10 for 8 cycles then stop
  if 3 restarts within 5 cycles then timeout
  group server

#Monitoring slapd process.

check process slapd with pidfile /var/ldap/var/run/slapd.pid
    start program = "/etc/init.d/slapd start"
    stop program  = "/etc/init.d/slapd stop"
    if failed port 389 then restart
    if 2 restarts within 3 cycles then timeout
    group server

    # monit will only monit/give alert in this mode.
    mode passive         

# Check Database file, size,permission etc...
check file slapd-database with path /var/ldap/var/openldap-data/mydata.db
   if failed permission 700 then alert
   if failed uid data then alert
   if failed gid data then alert
   if timestamp > 15 minutes then alert
   if size > 100 MB then alert

#Check directory for permission.       
check directory bin with path /bin
    if failed permission 755 then unmonitor
    if failed uid 0 then unmonitor
    if failed gid 0 then unmonitor

#Check host for which services up/down on particular port.
check host test.com with address 192.168.1.9
    if failed icmp type echo with timeout 4 seconds then alert
    if failed port 21 then alert
    if failed port 22 type tcp 22 with timeout 40 seconds then aler
    if failed port 80 protocol http then alert
    if failed port 389 type tcp with timeout 15 seconds then alert

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.

 

 


Posted by Steve (82.41.xx.xx) on Mon 10 Oct 2005 at 13:12
[ Send Message | View Steve's Scratchpad | View Weblogs ]

After reading this I setup simple monitoring of my host, with a few services:

  • Apache
  • Bind
  • ClamAV
  • Exim4
  • MySQL
  • OpenSSH

You can see the configuration file here.

I figured it is worth posting since the paths all match the Debian system...

Steve
--

[ Parent | Reply to this comment ]

Posted by Anonymous (65.205.xx.xx) on Mon 10 Oct 2005 at 13:16
This looks a lot simpler to setup and administer then Nagios, if not as flexible or complete. I've got Nagios monitoring a couple dozen boxes. A nice thing that Nagios can do is to save non-critical alerts until business hours. I hate getting paged in the middle of the night for something stupid like /var went over 80% capacity, when it's been 79% for weeks. Nagios is a bit of a bear to configure, and it will not out of the box take any corrective action, only send aletrs and track uptime.

[ Parent | Reply to this comment ]

Posted by Anonymous (213.164.xx.xx) on Mon 10 Oct 2005 at 16:10
True. I use Nagios a lot.

If you set up the templates correctly, the only noticable time you need to invest in nagios is the initial setup.

i.e. have a "web server" template, a "mail server" template, etc.

[ Parent | Reply to this comment ]

Posted by ajt (84.12.xx.xx) on Mon 10 Oct 2005 at 21:30
[ Send Message | View Weblogs ]
That was really easy to set-up and use.

Many thanks for a great article, MOST useful.

--
"It's Not Magic, It's Work"
Adam

[ Parent | Reply to this comment ]

Posted by sh4rk (212.39.xx.xx) on Tue 11 Oct 2005 at 07:08
[ Send Message ]
I use Zabbix. Kicks ass, check out http://www.zabbix.org

[ Parent | Reply to this comment ]

Posted by atrixnet (69.152.xx.xx) on Mon 16 Jun 2008 at 08:45
[ Send Message | View Weblogs ]
I for one, hate zabbix. That's my $.02

[ Parent | Reply to this comment ]

Posted by Anonymous (194.204.xx.xx) on Tue 11 Oct 2005 at 10:02
About ZABBIX:
apt-cache search zabbix returns nothing..

When i was looking for monitoring soft i chose spong.
Spong in unmaintained for 2 years already but works
great and is more KISS than NAGIOS. I could
not get nagious to work, but spong was so simple
i even wrote a few plugins for it myself.

[ Parent | Reply to this comment ]

Posted by Anonymous (193.216.xx.xx) on Sun 6 Nov 2005 at 20:33
This is APT repository for zabbix (http://www.zabbix.com

To use this repository, insert this line to your sources.list:
deb http://www.opf.slu.cz/zabbix stable contrib #(for stable distribution)
deb http://www.opf.slu.cz/zabbix testing contrib #(for testing distribution)
deb http://www.opf.slu.cz/zabbix unstable contrib #(for unstable distribution)

Then install required packages.
* zabbix-server[testing,unstable] (server processess zabbix_suckerd, zabbix_trapperd)
* zabbix-agent[stable,testing,unstable] (staticaly linked agent without dependencies, possible to install everywhere)
* zabbix-doc[stable,testing,unstable]
* zabbix-frontend-php[testing,unstable] (PHP frontend to administration)

[ Parent | Reply to this comment ]

Posted by bacula (195.14.xx.xx) on Thu 17 Aug 2006 at 12:29
[ Send Message | View Weblogs ]
if you want to install zabbix in debian linux Follow this step by step installation guide with screenshots

[ Parent | Reply to this comment ]

Posted by Anonymous (193.158.xx.xx) on Tue 11 Oct 2005 at 13:08
I use a combination of nagios and munin - munin is really easy to configure and quite extensible.

http://www.linpro.no/projects/munin/
or apt-cache search munin

[ Parent | Reply to this comment ]

Posted by Anonymous (81.57.xx.xx) on Tue 11 Oct 2005 at 13:31

'mon' is a good alternative, too.
More feature complete but not more complex to setup.

http://www.kernel.org/pub/software/admin/mon/html/

[ Parent | Reply to this comment ]

Posted by Anonymous (70.176.xx.xx) on Fri 14 Oct 2005 at 18:30
I use Nagios extensively. To me, for service monitoring Nagios is MUCH better- it gives you a real world "Can it be seen from outside" view. Then again, I run a massive network and my Nagios configs are > 40,000 lines.

I just deployed monit on a few servers last month and I have been very impressed with it. IMO, this and nagios are not in the same category- I use monit for some security checking (md5sums of binaries) and making sure services restart properly on failure.

[ Parent | Reply to this comment ]

Posted by hardik (61.95.xx.xx) on Tue 15 Nov 2005 at 11:33
[ Send Message ]
That is the main benefits, That Monit can supervise the service, if failed, It will restart the service. Before Monit, I was use runit and runit-run for super vision of the service. But i have to make lot of run script for that.
And compare to that Monit is very easy.
Cheers,
Hardik Dalwadi.

[ Parent | Reply to this comment ]

Posted by Anonymous (80.139.xx.xx) on Fri 14 Oct 2005 at 19:30
nice work :-)

but, please move

/etc/monitrc

to

/etc/monit/monitrc

cu icewalker

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Fri 14 Oct 2005 at 20:32
[ Send Message | View Steve's Scratchpad | View Weblogs ]

Done. Thanks for the notice.

Steve
--

[ Parent | Reply to this comment ]

Posted by hackeron (212.36.xx.xx) on Mon 24 Oct 2005 at 13:52
[ Send Message ]
Is there a comparison somewhere evaluating the opensource monitoring solutions available?

Currently, we monitor ~100 servers with Nagios for fault reporting and cacti for graphing load averages for memory, cpu, network utilization, etc (tt uses rrdtool internally and produces some nice looking graphs).

[ Parent | Reply to this comment ]

Posted by Anonymous (211.14.xx.xx) on Tue 9 May 2006 at 01:35
this line has a 22 too much after tcp:

if failed port 22 type tcp 22 with timeout 40 seconds then alert

you need to remove 22 after "tcp" or it will fail

[ Parent | Reply to this comment ]

Posted by edavey (81.6.xx.xx) on Tue 24 Apr 2007 at 00:52
[ Send Message ]

Ilya Grigorik has written a detailed HOWTO for using Monit to manage Mongrel processes for serving Ruby on Rails applications. It's here:

http://www.igvita.com/blog/2006/11/07/monit-makes-mongrel-play-ni ce/

ED

[ Parent | Reply to this comment ]

Posted by pizu (83.142.xx.xx) on Mon 22 Feb 2010 at 12:48
[ Send Message ]
wow. nice :D

now i have a problem..
is is what I am having:-

debbie://etc/monit# monit -t
Control file syntax OK

debbie://etc/monit# /etc/init.d/monit start
: command not found line 5:

Any idea? my email is pizpower@gmail.com

Thanks,
David Micallef

[ Parent | Reply to this comment ]

Posted by Anonymous (89.159.xx.xx) on Wed 16 Feb 2011 at 15:05
Hello,
I know this post is old but i had the same problem and did not found the answer but i managed to find a solution :

put this three command in your shell:
aptitude install tofrodos (this package contain command dos2unix)
dos2unix /etc/default/monit (delete the invisible ^M due to notepad)
/etc/init.d/monit/start

It worked for me ! hope it will help someone...

[ Parent | Reply to this comment ]

Posted by pizu (195.158.xx.xx) on Wed 16 Feb 2011 at 16:44
[ Send Message ]
Hey,

Thanks for your reply, unfortunately I removed Everything and m working with another software :)

Thanks anyway for your help.

Pizu

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

Which init system are you using in Debian?






( 1055 votes ~ 6 comments )

 

 

Related Links