Wednesday, June 22, 2011

Installing Configuring and Using Monit in Ubuntu

This is so straight forward and well documented in the Monit project that I wouldn't post about this if not just to allow those users that are starting with Linux and monitoring is their next concern.

The steps here should allow the user to install monit and monitor Google home page in no more than 5 minutes. It is always gratifying to get things running while following simple steps. Dealing with environment issues is the most difficult and frustrating part when you are trying to prove your concept.

  1. Install monit:
    sudo apt-get install monit
    
  2. Using sudo edit /etc/default/monit to setup automatic monit startup
    #startup=1
    START=yes
    
  3. Using sudo edit /etc/monit/monitrc as per the content below. Customize your web interface password, an IP allowed to connect via WEB (if you are a GUI guy), email addressee for alerts and mailserver. The rest of the settings should be OK for you. Note that the only check I am providing is checking Google availability just as a proof of concept. The web is full of samples to monitor anything in your servers
    ##################################################################
    
    # CUSTOM MONIT SETTINGS
    
    ##################################################################
    
    set mail-format {
    
      subject: [ $SERVICE ] $EVENT - $DATE
    
      message: Action: $ACTION, Description: $DESCRIPTION, Service: $SERVICE, Tested From Host: $HOST }
    
    # number of seconds between monit checks
    
    set daemon 60
    
    # Location of the monit log file
    
    # /var/log/messages is just ok
    
    # set logfile /var/log/monit.log
    
    set logfile syslog facility log_daemon
    
    # Change to the email address you want alerts to be sent to
    
    set alert nestorurquizaappmon@nestorurquiza.com
    
    # Port that the monit status page can be viewed
    
    set httpd port 2812
    
    # Allow localhost to connect
    
    allow localhost
    
    # The next line must be included to allow access from your computer
    
    # change the number to what your local ip is
    
    allow 0.0.0.0
    
    # The next line assigns a username:password combination to login.
    
    # Please change the password to something random.
    
    allow admin:myAdminPassword
    
    # Set the mailserver to send notification email.
    
    set mailserver mail.nestorurquiza.com
    
    ################################################################# 
    #REMOTE GOOGLE CHECKS
    ################################################################
    check host google-test with address google.com
      if failed port 80 proto http then alert
    group server
    
  4. Start, stop, restart, force reload as needed
    sudo /etc/init.d/monit start
    sudo /etc/init.d/monit stop
    sudo /etc/init.d/monit restart
    sudo /etc/init.d/monit force-reload
    
  5. See monit status, summary, unmonitor or monitor all as needed
    sudo monit status
    sudo monit summary
    sudo monit monitor all
    sudo monit unmonitor all
    
  6. Get extra help. Learn how to start or stop processes. Master monit!
    sudo monit -h
    
  7. If you prefer a GUI then get it with the below URL (Use the password you set)
    http://monit.server.address:2812/
    

Updating monit

Updating monit is easy. Just use this POB Recipe

6 comments:

Marcelo Olivas said...

I've not use Monit. I used Nagios but the installation has been a pain. Specially in previous releases. They (Nagios) have gotten better, but I always heard from my sysadmin buddies that Monit is much better than Nagios. As always, nice post Nestor! Let me look into Monit to compare it to Nagios.

sghael said...

couple of tweaks for updating Monit:

make sure libpam-dev is installed

apt_get('libpam-dev')

and specify the prefix on configuration, with bin dir:

./configure --prefix=/usr/sbin --bindir=/usr/sbin --sysconfdir=/etc/monit/

Anonymous said...

1) monit is good for checking local processes and system state.

2) nagios is good for checking if the host dies or loses network connectivity.

I moved all the process checks I was performing with Nagios to monit. Nagios became a simple ping check.

Nestor Urquiza said...

@Paul we use monit to check if the host is down as well. Just have an external monitoring server (or cluster of them), preferably physical box, and check for protocol and port of your servers. You can check from ICMP to application layer logic. I have not found a use case where I needed to look for alternatives, monit had covered our needs so far.

Nestor Urquiza said...

@sghael: Thanks for the input. That indeed is needed otherwise you might end up with two monit instances one in /usr/sbin and the other below /usr/local/bin. Definitely we want to avoid that. In fact in Ubuntu the default install puts monit in /usr/bin so it makes sense to keep installing it there. I have updated the configure statement now and packaged everything in a POB recipe.

Nestor Urquiza said...

@Marcelo Thanks for your words. I have not used Nagios. Monit is really simple and reliable indeed.

Followers