Operations 12 min read

Master Linux Monitoring with Monit: Installation, Configuration, and Real‑World Examples

This guide walks you through installing Monit on Ubuntu and CentOS, handling common build issues, configuring the web UI, setting up email alerts, and creating practical monitoring rules for processes, filesystems, files, custom scripts, and remote hosts.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux Monitoring with Monit: Installation, Configuration, and Real‑World Examples

Monit is a lightweight monitoring tool for Linux that can watch system resources, processes, files, directories, and devices, automatically restart failed services, and provide a built‑in web UI with color‑coded status indicators and email notifications.

Installation

On Ubuntu, install Monit with: sudo apt-get install monit On CentOS, use: yum install monit For source installation:

wget http://mmonit.com/monit/dist/monit-5.5.tar.gz
tar zxvf monit-5.5.tar.gz
cd monit-5.5
./configure --prefix=/usr
make
make install

If configure reports missing PAM headers, install the development package: apt-get install libpam0g-dev For SSL library errors, install the SSL development package and, if necessary, point configure to the library directory:

sudo apt-get install libssl-dev
./configure --prefix=/usr --with-ssl-lib-dir=/usr/lib/i386-linux-gnu/

After compilation, copy the sample configuration file and set proper permissions:

mv monitrc /etc/monitrc
chown root:root /etc/monitrc
chmod 0700 /etc/monitrc

Starting Monit and Web UI

Start the daemon: monit The built‑in HTTP server listens on port 2812. A basic configuration looks like:

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

To allow remote access, modify the address and credentials:

set httpd port 2812 and
    use address 10.64.74.99
    allow 0.0.0.0/0.0.0.0
    allow manu:manu

Now the UI can be reached at http://10.64.74.99:2812.

Basic Settings

set daemon 60               # check every 60 seconds
set logfile /var/log/monit.log

Email Alerts

set mailserver xxx.xx.xxx.xxx port 25 with timeout 15 seconds
set mail-format {
    from: [email protected]
    subject: monit alert -- $EVENT $SERVICE
    message: $EVENT Service $SERVICE
    Date: $DATE
    Action: $ACTION
    Host: $HOST
    Description: $DESCRIPTION
    Your faithful employee,
    bean
}
set alert [email protected]

Monitoring Examples

1. Process Monitoring

check process apache with pidfile /var/run/httpd.pid
    start program = "/etc/init.d/rcWebServer.sh start https"
    stop program = "/etc/init.d/rcWebServer.sh stop https"
    if changed pid then alert

For processes without a PID file, use matching on the command line:

check process test_abc with MATCHING test_abc
    if changed pid then alert

2. Filesystem / Device Monitoring

check device VAR_LOG with path /var/log
    if space usage > 85% then alert

check filesystem tmpfs with path /var
    if space usage > 80% then alert

3. File Monitoring

check file monit_target with path /var/log/monit_target
    if failed permission 700 then alert
    if size > 1000 MB then exec "/usr/local/bin/rotate /var/log/monit_target"

4. Program Monitoring (Custom Script)

check program COREDUMP_EXIST with path "/var/log/tool/coredump_exist.sh"
    if status != 0 then alert

#!/bin/sh
corefile_num=`ls /home/manu/core/core* 2>/dev/null | wc -l`
if [ $corefile_num -eq 0 ]; then
    exit 0
else
    exit 1
fi

5. Host Monitoring

check host my_brother with address XX.XX.XX.XX
    if failed icmp type echo count 3 with timeout 3 seconds then alert

For detailed options, refer to the official Monit documentation at http://mmonit.com/monit/documentation/monit.html#connection_testing .

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ConfigurationSystem AdministrationLinux monitoringprocess monitoringMonitemail alerts
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.