Monit is an open source program used to monitor services on Linux systems and ensure they are always online. If for any reason the program shuts down, Monit will try to bring it back online and make it stay online consistently.
Monit also comes with a web interface that you can use to control and monitor the state of your application/process. In this guide, we’ll cover installation and configuration of monit on Ubuntu 22.04|20.04|18.04
Install Monit on Ubuntu 22.04|20.04|18.04
Monit package is available on official Ubuntu repositories. Install it using the command:
sudo apt update && sudo apt install monit -y
To start the process, use systemctl command available on Ubuntu system.
sudo systemctl enable --now monit
Check if the service is running:
$ systemctl status monit
● monit.service - LSB: service and resource monitoring daemon
Loaded: loaded (/etc/init.d/monit; generated)
Active: active (running) since Wed 2023-08-16 02:30:31 UTC; 29s ago
Docs: man:systemd-sysv-generator(8)
Tasks: 1 (limit: 4523)
Memory: 2.1M
CPU: 33ms
CGroup: /system.slice/monit.service
└─1490 /usr/bin/monit -c /etc/monit/monitrc
Aug 16 02:30:31 jammy systemd[1]: Starting LSB: service and resource monitoring daemon...
Aug 16 02:30:31 jammy monit[1484]: * Starting daemon monitor monit
Aug 16 02:30:31 jammy monit[1484]: ...done.
Aug 16 02:30:31 jammy systemd[1]: Started LSB: service and resource monitoring daemon.
Monit configuration files are located under /etc/monit/ directory.The main configuration file is /etc/monit/monitrc. This file is highly commented out, you can reference it for all configs. By default all files located on /etc/monit/conf.d/ and /etc/monit/conf-enabled/ are read by monit when it is started, you can place your process monitoring configurations on this directory to keep things organized.
Enable Monit HTTP interface
Monit has an embedded HTTP interface which can be used to view the status of services monitored and manage services from a web interface. By default monit HTTP interface is not enabled, enable it by uncommenting the following lines on /etc/monit/monitrc file.
$ sudo vim /etc/monit/monitrc
set httpd port 2812 and
use address localhost # only accept connection from localhost
allow localhost # allow localhost to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
You can change admin:monit with username and password you want to use. To allow access from a different IP, add it like below:
allow 192.268.1.20
Restart monit after making the change:
sudo systemctl restart monit
#OR
sudo monit reload
Check the status of Monit
Typing monit status command will display details about monit status.
$ sudo monit status
Monit 5.31.0 uptime: 0m
System 'jammy'
status OK
monitoring status Monitored
monitoring mode active
on reboot start
load average [0.07] [0.05] [0.01]
cpu 0.0%usr 0.0%sys 0.0%nice 0.0%iowait 0.0%hardirq 0.0%softirq 0.0%steal 0.0%guest 0.0%guestnice
memory usage 390.0 MB [10.2%]
swap usage 0 B [0.0%]
uptime 31m
boot time Wed, 16 Aug 2023 02:01:26
filedescriptors 1056 [0.0% of 9223372036854775807 limit]
data collected Wed, 16 Aug 2023 02:33:17
To check configuration files syntax, use:
$ sudo monit -t
Control file syntax OK
Check monitored processes summary:
$ sudo monit summary
Monit 5.25.1 uptime: 6m
┌─────────────────────────────────┬────────────────────────────┬───────────────┐
│ Service Name │ Status │ Type │
├─────────────────────────────────┼────────────────────────────┼───────────────┤
│ ubuntu18.04.computingforgeek... │ OK │ System │
└─────────────────────────────────┴────────────────────────────┴───────────────┘
Monitoring Processes/Programs with Monit
I’ll do a demo of how to monitor a process with monit. On my local machine, I have apache2 and MariaDB running programs. I’m going to create a custom configuration file for the two on /etc/monit/conf.d/custom.conf.
# Apache configuration
check process apache2 with pidfile /run/apache2/apache2.pid
start program = "/bin/systemctl start apache2" with timeout 60 seconds
stop program = "/bin/systemctl stop apache2"
# MariaDB configuration
#
check process mariadb with pidfile /run/mysqld/mysqld.pid
start program = "/bin/systemctl start mariadb" with timeout 60 seconds
stop program = "/bin/systemctl stop mariadb"
# Docker configuration
#
check process docker with pidfile /run/docker.pid
start program = "/bin/systemctl start docker" with timeout 60 seconds
stop program = "/bin/systemctl stop docker"
Note that “start program” and “stop program” command needs to be an absolute path, e.g /bin/systemctl instead of systemctl.
Check for syntax errors after making the change:
$ sudo monit -t
Control file syntax OK
If all is Okay, reload monit configuration file for it to read new changes.
$ sudo monit reload
Reinitializing monit daemon
Now check the summary of process list being monitored:
$ sudo monit summary
Monit 5.25.1 uptime: 41m
┌─────────────────────────────────┬────────────────────────────┬───────────────┐
│ Service Name │ Status │ Type │
├─────────────────────────────────┼────────────────────────────┼───────────────┤
│ ubuntu18.04.computingforgeek... │ OK │ System │
├─────────────────────────────────┼────────────────────────────┼───────────────┤
│ apache2 │ OK │ Process │
├─────────────────────────────────┼────────────────────────────┼───────────────┤
│ mariadb │ OK │ Process │
├─────────────────────────────────┼────────────────────────────┼───────────────┤
│ docker │ OK │ Process │
└─────────────────────────────────┴────────────────────────────┴───────────────┘
To start running all of the monitored programs.
sudo monit start all
Access Monit Web Interface:
To access the web interface use the URL:
http://[ip-address|domain]:2812
Login with the username as “admin” and password as “monit”.
To allow access to port from remote IP addresses on the firewall, run:
$ sudo ufw allow 2812
Rule added
Rule added (v6)
Monit’s web interface looks like this.
Click on the service name to get process details including stop and start buttons:
More on Monitoring:
Install Sensu Monitoring Tool on Ubuntu
How To Install Zabbix Server 5.0 on Ubuntu
Install and Configure Nagios 4 on Ubuntu