Introduction
Monitoring the performance and health of a Linux system (running services) is crucial for maintaining uptime and ensuring applications run smoothly. Monit is a powerful, lightweight tool designed to simplify system monitoring and management. This article explores how Monit can be used to effectively monitor Linux systems, covering its key features, setup process, and configuration examples.
I tested Monit on Ubuntu 22.04 Desktop, and below is my configuration. I used a lot of standard configuration. My idea is to install it parallel with WordPress server to monitor my WordPress environment.
What is Monit?
Monit is a simple application that I use to manage services and monitor performance on Ubuntu servers. The application has the ability to restart services that are not running, and can send alert notifications in case defined resource usage thresholds are exceeded.
You can check manual page at the link .
Key Features of Monit
- Process Monitoring: Monit can check if a process is running and restart it if it crashes.
- File System Monitoring: It can monitor file attributes like timestamps and checksums.
- Resource Monitoring: Monit can track CPU and memory usage to identify resource bottlenecks.
- Remote Monitoring: Monit includes a web interface for remote monitoring and management.
- Alerting: It can send alerts via email when a service or system requires attention.
- Automatic Restart: If a service fails, Monit can automatically attempt to restart it.
Setting Up Monit

Monit Installation on Ubuntu Server
To install Monit on a Debian-based system, use:
sudo apt update
sudo apt install monit
Monit is available in most Linux distributions’ package repositories.
Monit
Configuration
Please check the following link about more configuration examples.
Monit’s configuration file is typically located at /etc/monit/monitrc
. I installed it on my Ubuntu Desktop 22.04 and tested it on this system.
You have to edit this file to define what Monit will monitor and how.
Step 1. Create Backup and Remove Defaulf Configuration
# Create a backup
sudo cp /etc/monit/monitrc /etc/monit/monitrc.bkp
# Clean the file
sudo echo " " > /etc/monit/monitrc
Step 2. Enable the Web Interface and Users – Example
- To enable the web interface, uncomment and modify the following lines in the configuration file:
- In this case application will be available on the port 2812
set httpd port 2812 and
# only accept connection from localhost
use address localhost # only accept connection from localhost -> Comment this line to enable connection from outside your network!
# allow localhost to connect to the server
allow localhost
# require user 'admin' with password 'monit'
allow admin:monit
Step 3: Create Monitoring Services – More examples
Monit monitoring is a modular application so the user can decide completely which module they want to monitor. Below I will give you a few suggestions and my full configuration is below.
Apache HTTP Server Monitoring
Here is an example of configuring Monit to monitor the Apache HTTP server:
check process apache with pidfile /var/run/apache2/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed host 127.0.0.1 port 80 protocol http then restart
if 5 restarts within 5 cycles then timeout
Disk I/O Monitoring
Monitor disk read/write performance and detect potential bottlenecks:
check device sda with path /dev/sda
if read rate > 100 MB/s for 5 cycles then alert
if write rate > 100 MB/s for 5 cycles then alert
Network Connectivity Check (Ping)
Ensure the server can reach the internet or specific services.
check host google-dns with address 8.8.8.8
if failed ping then alert
My Example of Configuration File
# Clean the file
sudo echo " " > /etc/monit/monitrc
sudo nano /etc/monit/monitrc
set daemon 15
set logfile /var/log/monit.log
set alert user@optimusing.com
set httpd
port 2812 # set port for the application
use address localhost # only accept connection from localhost -> Comment this line to enable connection from outside your network!
# allow localhost
allow youruser:yourpassword # set user and password
# Check MySQL
check host localmysql with address 127.0.0.1
if failed ping then alert
if failed port 3306 protocol mysql then alert
# Check php-fpm
check process phpfpm with pidfile /run/php/php7.0-fpm.pid
if cpu > 70% for 2 cycles then alert
if total cpu > 90% for 5 cycles then restart
if memory > 600 MB then alert
# if total memory > 800 MB then restart
# Check Apache
check process apache with pidfile /var/run/apache2/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed host 127.0.0.1 port 80 protocol http then restart
if 5 restarts within 5 cycles then timeout
if cpu > 70% for 2 cycles then alert
if memory > 600 MB then alert
# Check Network
check network enp0s3 with interface enp0s3
if failed link then alert
if changed link then alert
if saturation > 80% then alert
if download > 10 MB/s then alert
if upload > 10 MB/s then alert
# include files for individual sites
include /etc/monit.d/*
If you change the configuration file, the application must be stopped and restarted for it to take effect:
sudo monit -t
sudo systemctl stop monit
sudo systemctl start monit
Testing the Configuration
After configuring Monit, test the configuration file with the following command:
sudo monit -t
If the configuration is correct, start Monit:
Enable Monit Service
sudo systemctl start monit
sudo systemctl enable monit
Access to the Monit Application
To access to the monit applicaiton open your browser and open the address:
http://IP-ADDRESS-OF-THE-SERVER:2812
Monitoring with Bash Scripts
If you are interested in monitoring, for example disk usage with email alerting using a Bash scripts, check the link.