Complete Guide to Installing and Configuring Monit for Effective Monitoring

Installation

Monit can be effortlessly installed through apt-get:

$ sudo apt-get install monit

After installation, programs and processes can be added to the configuration file:

$ sudo nano /etc/monit/monitrc

Start Monit using the monit command to keep it running in the background:

$ monit

To view Monit’s details, use the command monit status:

The Monit daemon 5.3.2 uptime: 1h 25m
...

Configuring Monit

Monit is easily configurable out of the box. Default settings include checking services every 2 minutes and storing logs in “/var/log/monit.log”. These settings can be modified at the beginning of the configuration file using the set daemon and set logfile lines.

Web Service

Monit features its own web server running on port 2812. To configure the web interface, uncomment the section beginning with set httpd port 2812. Add your server’s IP or domain name, allow connections, and create a Monit user and password.

set httpd port 2812
use address 12.34.56.789
allow 0.0.0.0/0.0.0.0
allow admin:monit

After configuring, reload Monit for the changes to take effect:

$ monit reload

Access the web interface at http://12.34.56.789:2812. A dialog box will appear in the browser.

General Monit Scripts

Sidekiq

check process sidekiq_thepact_staging0 with pidfile "/home/deployer/www/staging/shared/tmp/pids/sidekiq.pid"
...

PostgreSQL

check process postgres with pidfile /var/run/postgresql/9.5-main.pid
...

Puma

check process puma with pidfile /var/www/myapp/production/shared/tmp/pids/puma.pid
...

Using the Scripts

By default, Monit does not load conf-scripts in conf-available. To execute them, link the scripts in conf-enabled instead of duplicating them.

$ sudo ln /etc/monit/conf-available/puma /etc/monit/conf-enabled/puma

Sources