preload preload preload preload

Monit a service monitoring tool in linux

monit-logo.gif Monit is a utility for managing and monitoring processes, files, directories and devices on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses to much resources. You may use monit to monitor files, directories and devices for changes, such as timestamps changes, checksum changes or size changes.  Monit will monitor a service and in case of any problems monit will will raise an email alert.

Install the package monit using apt on Ubuntu.

$ sudo apt-get install monit

First edit the file  /etc/default/monit and change startup=0 to  startup=1. The file should look like below text.

# Defaults for monit initscript
# sourced by /etc/init.d/monit
# installed at /etc/default/monit by maintainer scripts
# Fredrik Steen <stone@debian.org>
# 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

Edit the monit configuration file /etc/monit/monitrc and uncomment the following lines

$ sudo vim /etc/monit/monitrc

Start monit in background (run as daemon) and check the services at 2-minute intervals.

set daemon  120

You can set the alert recipients here, which will receive the alert for each service. The event alerts may be restricted using the list.

set alert abc@xyz.com                                   # receive all alerts
set alert hij@xyz.com only on { timeout }       # receive just service-

Monit has an embedded webserver, which can be used to view the configuration, actual services parameters or manage the services using the web interface.

set httpd port 2812 and
     use address localhost  # only accept connection from localhost
     allow localhost        # allow localhost to connect to the server and
     allow admin:monit      # require user 'admin' with password 'monit'

Next session in the configuration file is where the monit monitors the services,  for that we need to specify the service which needs to be monitored. A sample example for monitoring apache is as follows.

check process apache with pidfile /var/run/apache2.pid
    start program = "/etc/init.d/apache2 start"
    stop program  = "/etc/init.d/apache2 stop"
    if cpu > 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

For more examples click here
Next we will see some monit commonds.

To satrt monit

$ sudo /etc/init.d/monit start

To start the services which the monit is monitorin, sudo monit start all will start all the services in the monit configuration file, if specify a name insted of start all monit will start only the specified service.

$ sudo monit start all
$ sudo monit start apache

To get the status of monit services

$ sudo monit status

To get the summary of mont services

$ sudo monit summary

To stop all the services monitored my monit use stop all, or specify the name of the servive you need to stop

$ sudo monit  stop all
$ sudo monit stop apache

For more help click here

  • Share/Bookmark
  • Leave a Reply

    * Required
    ** Your Email is never shared