Using Monit process monitoring on Ubuntu/Debian

Monit is an open-source monitoring tool for Linux operating systems. This article guides you through a basic Monit setup on Ubuntu/Debian.

Installation

sudo apt-get update
sudo apt-get install monit

Configuration

The main configuration file is located at /etc/monit/monitrc. Open it for editing:

sudo nano /etc/monit/monitrc

Enable the web interface

Uncomment and adjust the following lines to enable the HTTP status interface:

set httpd port 2812 and
    use address localhost
    allow localhost
    allow admin:monit

Change admin:monit to a username and password of your choice.

Monitor a process

Add a service check block. For example, to monitor nginx:

check process nginx with pidfile /var/run/nginx.pid
  start program = "/etc/init.d/nginx start"
  stop program  = "/etc/init.d/nginx stop"
  if failed host 127.0.0.1 port 80 protocol http then restart
  if 5 restarts within 5 cycles then timeout

Monitor system resources

check system localhost
  if loadavg (1min) > 4 then alert
  if memory usage > 75% then alert
  if cpu usage (user) > 70% then alert

Starting Monit

sudo service monit start
sudo update-rc.d monit enable

Useful commands

# Check Monit status
sudo monit status

# Test configuration syntax
sudo monit -t

# Reload configuration
sudo monit reload

# Stop a monitored service
sudo monit stop nginx

# Start a monitored service
sudo monit start nginx

Accessing the web interface

Open a browser and navigate to:

http://your-server-ip:2812

Log in with the credentials configured in monitrc.

On this page