Monit is a quick setup, easy-to-use but effective program for monitoring server services. It can also include important basics like CPU usage, disk usage, and more. If a server service fails, it can be restarted automatically. In the event of problems, one or more recipients will be informed by email.
Originally intended for a single server, M / Monit also offers a commercial version that can monitor several servers at the same time (under one interface).
What can we monitor using Monit?
We can monitor multiple things using Monit such as Processes, resources such as overall CPU usage, Memory, and Load Average; server or machine uptime, various server applications, network connections to various network services; hard disk or a filesystem; monitor files for changes such as md5 or sha1 checksum of files, timestamp, size change, and more including folder changes.
M/Monit installation on Ubuntu 20.04 Linux
Open the command terminal and simply type the below-given command. This tool package is there on Ubuntu’s repo and it doesn’t need any third-party repository help.
sudo apt-get install monit
The Monit program can be configured using the
/etc/monit/monitrc file. There are numerous sample settings, some of which are commented out, which are self-explanatory, or whose comments contain help texts. We recommend that you do not make your settings directly in this file. It is better to create a new one –
nano /etc/monit/conf.d/ for the desired settings.
Enable m/Monit httpd port on Ubuntu
By default, port 2812 to communicate Monit will be disabled and has to be enabled by editing its configuration file.
sudo nano /etc/monit/monitrc
Find the line: set httpd port 2812
There remove the # tag for the following lines. Also, replace the allow and use address value from localhost to 0.0.0.0 if you want to access the Monit web interface remotely as shown in the screenshot.
You can also change the default password for the admin that is monit.
set httpd port 2812 and use address 0.0.0.0 # only accept connection from localhost (drop if you use M/M> allow 0.0.0.0/0 # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit'
Save the file by pressing Ctrl+X and then type – Y and hit the Enter key.
Check and load
To check configuration files are without any errors use the following command:
sudo monit -t # If there are no errors, you will receive the following feedback: # Control file syntax OK
Enable Monit service on Linux
By default it would not be enabled, thus to do that, run the command to enable the service to get started automatically with the system boot.
sudo /lib/systemd/systemd-sysv-install enable monit
Restart it once
sudo systemctl restart monit
To know everything is working fine run-
sudo monit status
Allow M/Monit port in the firewall
To access the Monit web interface outside your local host, allow its port or service in the firewall to access the public network.
sudo ufw allow 2812
Access Web Interface
Open a browser on the local or remote system that can access the Ip-address of the server/pc where the Monit Monitor system has been installed. And point it to
Enter username and password.
Add services to Monitor in Monit
You can either create a service file for a tool to monitor or can use the pre-configured ones available in the M/Monit folder.
/etc/monit/conf-available/ there are several ready-made files for various common server services, the defaults of which can usually be adopted. Such as:
acpid, at, mdadm, mysql, openntpd, pdns-recursor, rsyslog, snmpd, apache2, cron, memcached, nginx, openssh-server, postfix and smartmontools.
For Monit to take over the settings for the desired service, a soft link to the service file must be created and activated in the
We want to monitor Apache using its pre-configured file. Thus for that-
sudo ln -s /etc/monit/conf-available/service-file /etc/monit/conf-enabled/
example for Apache :
sudo ln -s /etc/monit/conf-available/apache2 /etc/monit/conf-enabled/
To make the changes effective Monit daemon needs to be reloaded.
sudo monit reload
In the same way, we can enable other services.
Manually Add Service
Now, if you want to add some service manually, then you have to create a file for the same. For example, you want to detect all information about your system hardware using sensors.
sudo apt install lm-sensors sudo nano/etc/monit/conf-available/sensors
check program sensors with path /usr/bin/sensors if status != 0 then alert
Save the file: Ctrl+X, Y, and hit the Enter Key.
sudo ln -s /etc/monit/conf-available/sensors /etc/monit/conf-enabled/
sudo monit reload
In this way, we can monitor our system using the lightweight M/Monit tool on Ubuntu Linux. To know more about it see the official documentation.