≡ Menu

How to Install and Configure Monit on Linux for Process Monitoring

Monit is an open source utility that provides several system monitoring functionality that are extremely helpful to sysadmins. This article provides a jumpstart guide on monit installation and configuration. We also discuss a specific example related to processes monitoring.

1. Install monit

On Fedora, openSUSE, Debian install monit as a package from the distribution repository. For example, on Debian (and Ubuntu), install monit using apt-get as shown below.

# apt-get install monit

If your distribution don’t have the monit package, download monit source and install it.

2. Configure monit

A sample process monitoring entry in the monit configuration file /etc/monit/monitrc looks like the following.

check process PROCESSNAME
        with pidfile PIDFILENAME-WITHABSOLUTE-PATH
        start = STARTUP-SCRIPT
        stop = STOP-SCRIPT

For example, to monitor the cron daemon, append the following lines to the monitrc file.

# vim /etc/monit/monitrc
check process crond
            with pidfile /var/run/crond.pid
            start = "/etc/init.d/cron start"
            stop  = "/etc/init.d/cron stop"

For further configurations (for example, restarting a process when it crosses a memory or process limit), refer the HOW TO MONITOR section in “man monit”.

Also, enable syslog by uncommenting the following line in /etc/monit/monitrc.

# vim /etc/monit/monitrc
set logfile syslog facility log_daemon

3. Allow startup of monit

Edit the /etc/default/monit file and enable the start up flag, which ensures that the configuration is done so that monit can start.

# vim /etc/default/monit
startup=1

4. Start monit

# /etc/init.d/monit start
Starting daemon monitor: monit

5. Check monit functionality

To test this, let us kill the running cron daemon as shown below.

# ps -ef | grep cron
root      2886     1  0 10:18 ?        00:00:00 /usr/sbin/cron

# pkill -9 cron

In the next interval, monit automatically starts the cron daemon without the administrator interaction as shown in the syslog messages below.

Dec  5 13:06:55 (none) monit[2968]: 'crond' process is not running
Dec  5 13:06:55 (none) monit[2968]: 'crond' trying to restart
Dec  5 13:06:55 (none) monit[2968]: 'crond' start: /etc/init.d/cron

Do a ps -ef to make sure the cron job is started automatically by monit, when you killed it.

# ps -ef | grep cron
root     19728     1  0 13:06 ?        00:00:00 /usr/sbin/cron
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • chmurli November 29, 2010, 5:23 pm

    URL is wrong? I don’t think its the same program.

  • Michael Kang November 29, 2010, 7:36 pm
  • Ramesh Natarajan November 29, 2010, 10:59 pm

    @chmurli,

    M/monit and monit are related products. Both are hosted on the same website. If you have monit installed on multiple servers, you can use M/monit to monitor those servers from a web UI.

    @Michael,

    Thanks. I’ve updated the URL.

  • feorzakbar February 18, 2014, 7:32 am

    hi my name is akbar,i really loved ‘monit’,

    i tested in my localhost and it is working fine,but i want to install and configure it in my website server. i tried to put my website name like this by connecting to the server using ssh

    set httpd port 2812
    use address abc.website.com # only accept connection from localhost
    allow localhost # allow localhost to connect to the server and
    allow admin:admin # require user ‘admin’ with password ‘monit’

    but when trying to open the website in browser as abc.website.com:2812
    nothing happes loading loading
    please help me

  • erm3nda November 7, 2015, 9:12 pm

    @feorzakbar

    U should have default http-interface script inside /etc/monit/conf.d folder.
    In your code example you missed the “and” operator at first line end. Change “set httpd port 2812” to “set httpd port 2812 and”

    As you didn’t defined and, the script is “looping” inside that config mistake and does not end loading options like credentials, so i assume your monit never asked you about them at all.

  • Pankaj Grover May 13, 2016, 3:49 am

    @feorzakbar, It’s quite a bit late to reply. But It’d help others who are facing same problem.

    You just need to comment (put # ) the line starting from use address abc.website.com

    Restart monit !