Monit is an open-source monitoring tool that can be used to monitor servers. With Monit, you can monitor server processes and different services like Apache, Nginx, MySQL, FTP, SSH, Sendmail, and many more. It offers a simple and user-friendly Web UI to monitor all processes and services. Monit can start any service automatically in the event of failure. It also allows you to monitor remote hosts’ TCP/IP ports, server protocols, and ping via a command line interface.

This tutorial will show you how to install and configure the Monit monitoring tool on Ubuntu 22.04.

Prerequisites

  • A server running Ubuntu 22.04.
  • A root password is configured on the server.

Getting Started

First, you will need to update and upgrade all the packages to the latest version. You can do it with the following command:

apt update -y

apt upgrade -y

Once all the packages are installed, you can proceed to the next step.

Install Monit on Ubuntu 22.04

By default, the Monit package is available in the Ubuntu 22.04 default repository. You can install it using the following command:

apt-get install monit -y

after the successfull installation, start the Monit service and enable it to start at system reboot:

systemctl start monit

systemctl enable monit

You can also check the status of the Monit using the following command:

systemctl status monit

You will get the following output:

? monit.service - LSB: service and resource monitoring daemon
     Loaded: loaded (/etc/init.d/monit; generated)
     Active: active (running) since Mon 2022-08-01 04:28:17 UTC; 11s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 6292 ExecStart=/etc/init.d/monit start (code=exited, status=0/SUCCESS)
      Tasks: 1 (limit: 2242)
     Memory: 2.5M
        CPU: 25ms
     CGroup: /system.slice/monit.service
             ??6298 /usr/bin/monit -c /etc/monit/monitrc

Aug 01 04:28:17 ubuntu2204 systemd[1]: Starting LSB: service and resource monitoring daemon...
Aug 01 04:28:17 ubuntu2204 monit[6292]:  * Starting daemon monitor monit
Aug 01 04:28:17 ubuntu2204 monit[6292]:    ...done.
Aug 01 04:28:17 ubuntu2204 systemd[1]: Started LSB: service and resource monitoring daemon.

You can also check the Monit version using the following command:

monit --version

You should see the following output:

This is Monit version 5.31.0
Built with ssl, with ipv6, with compression, with pam and with large files
Copyright (C) 2001-2022 Tildeslash Ltd. All Rights Reserved.

Configure Monit Monitoring

Next, you will edit the Monit default configuration file and set the admin password and port. You can do it with the following command:

nano /etc/monit/monitrc

Change the following lines:

set httpd port 2812 and
allow admin:monit # require user 'admin' with password 'monit'

Save and close the file the restart the Monit service to apply the changes:

systemctl restart monit

By default, Monit listens on port 2812. You can check it using the following command:

ss -antpl | grep monit

You should see the following output:

LISTEN 0      1024         0.0.0.0:2812       0.0.0.0:*    users:(("monit",pid=6427,fd=6))                        
LISTEN 0      1024            [::]:2812          [::]:*    users:(("monit",pid=6427,fd=7))                        

You can also check your system status using the command below:

monit status

You will get the following output:

Monit 5.31.0 uptime: 0m

System 'ubuntu2204'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  load average                 [0.08] [0.13] [0.13]
  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                 1.0 GB [54.0%]
  swap usage                   0 B [0.0%]
  uptime                       28m
  boot time                    Mon, 01 Aug 2022 04:02:09
  filedescriptors              1728 [0.0% of 9223372036854775807 limit]
  data collected               Mon, 01 Aug 2022 04:29:55

Add Monitoring Services

Next, you will need to add the services that you want to monitor using Monit. In this section, we will add the Nginx and ProFTP services to Monit.

Add Nginx Monitoring Service

By default, Monit provides a pre-defined template for some of the processes and services. All these templates are located at /etc/monit/conf-available/ directory. By default, the Nginx template is available, so you just need to enable it using the following command:

ln -s /etc/monit/conf-available/nginx /etc/monit/conf-enabled/

Next, restart the Monit service to apply the changes:

systemctl restart monit

Add ProFTP Monitoring Service

By default, the ProFTP service template is not available. So you will need to create it using your favorite editor.

nano /etc/monit/conf-available/proftpd

Add the following lines:

check process proftpd with pidfile /var/run/proftpd.pid
   start program = "https://www.howtoforge.com/etc/init.d/proftpd start"
   stop  program = "https://www.howtoforge.com/etc/init.d/proftpd stop"
if failed port 21 protocol ftp then restart

Save and close the file, then enable the ProFTP service with the following command:

ln -s /etc/monit/conf-available/proftpd /etc/monit/conf-enabled

You can verify the template for any syntax error using the following command:

monit -t

You will get the following output:

Control file syntax OK

Next, restart the Monit service to apply the changes:

systemctl restart monit

Access Monit Web UI

Now, open your web browser and access the Monit web interface using the URL http://your-server-ip-2812. You should see all your services on the following screen:

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/p1.png6605a00e6f82a.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="261" loading="lazy" src="data:image/svg xml,” width=”318″>

Provide your username, password and click on the Sign in button. You should see the Monit dashboard on the following screen:

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/p2.png6605a00ec8e94.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="368" loading="lazy" src="data:image/svg xml,” width=”750″>

Click on the Nginx service. You should see the detailed information on Nginx on the following screen:

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/p4.png6605a00f33e66.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="372" loading="lazy" src="data:image/svg xml,” width=”750″>

Monitoring Monit Via Command Line

Monit also allows you to monitor all configured services through the command-line interface.

To see a quick summary of monit, run the following command:

monit summary

You should see the following output:

Monit 5.31.0 uptime: 0m
????????????????????????????????????????????????????????????????????????????????
? Service Name                    ? Status                     ? Type          ?
????????????????????????????????????????????????????????????????????????????????
? ubuntu2204                      ? OK                         ? System        ?
????????????????????????????????????????????????????????????????????????????????
? proftpd                         ? OK                         ? Process       ?
????????????????????????????????????????????????????????????????????????????????
? nginx                           ? OK                         ? Process       ?
????????????????????????????????????????????????????????????????????????????????
? nginx_bin                       ? OK                         ? File          ?
????????????????????????????????????????????????????????????????????????????????
? nginx_rc                        ? OK                         ? File          ?
????????????????????????????????????????????????????????????????????????????????

You can also see the status of all the services with the following command:

monit status

You will get detail information on all services in the following output:

Monit 5.31.0 uptime: 0m

Process 'proftpd'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  pid                          6806
  parent pid                   1
  uid                          0
  effective uid                115
  gid                          65534
  uptime                       2m
  threads                      1
  children                     0
  cpu                          -
  cpu total                    -
  memory                       0.2% [3.4 MB]
  memory total                 0.2% [3.4 MB]
  security attribute           unconfined
  filedescriptors              5 [0.5% of 1024 limit]
  total filedescriptors        5
  read bytes                   0 B/s [2.3 kB total]
  disk read bytes              0 B/s [0 B total]
  disk read operations         0.0 reads/s [17 reads total]
  write bytes                  0 B/s [2.1 kB total]
  disk write bytes             0 B/s [4 kB total]
  disk write operations        0.0 writes/s [8 writes total]
  port response time           3.791 ms to localhost:21 type TCP/IP protocol FTP
  data collected               Mon, 01 Aug 2022 04:34:49

Process 'nginx'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  pid                          6994
  parent pid                   1
  uid                          0
  effective uid                0
  gid                          0
  uptime                       1m
  threads                      1
  children                     1
  cpu                          -
  cpu total                    -
  memory                       0.1% [1.7 MB]
  memory total                 0.4% [7.1 MB]
  security attribute           unconfined
  filedescriptors              10 [1.0% of 1024 limit]
  total filedescriptors        21
  read bytes                   0 B/s [0 B total]
  disk read bytes              0 B/s [0 B total]
  disk read operations         0.0 reads/s [0 reads total]
  write bytes                  0 B/s [0 B total]
  disk write bytes             0 B/s [0 B total]
  disk write operations        0.0 writes/s [0 writes total]
  data collected               Mon, 01 Aug 2022 04:34:49

File 'nginx_bin'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  permission                   755
  uid                          0
  gid                          0
  size                         1.2 MB
  access timestamp             Mon, 01 Aug 2022 04:17:26
  change timestamp             Mon, 01 Aug 2022 04:17:24
  modify timestamp             Wed, 27 Apr 2022 10:56:57
  checksum                     8ae236b8cfaa5ba5f471ab7fba65700d (MD5)
  data collected               Mon, 01 Aug 2022 04:34:49

File 'nginx_rc'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  permission                   755
  uid                          0
  gid                          0
  size                         4.5 kB
  access timestamp             Mon, 01 Aug 2022 04:17:24
  change timestamp             Mon, 01 Aug 2022 04:17:24
  modify timestamp             Tue, 06 Nov 2018 19:04:12
  checksum                     290f6f12a12bc8e882bc5af46c1bfe7c (MD5)
  data collected               Mon, 01 Aug 2022 04:34:49

System 'ubuntu2204'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  load average                 [0.02] [0.11] [0.12]
  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                 1.0 GB [54.2%]
  swap usage                   0 B [0.0%]
  uptime                       33m
  boot time                    Mon, 01 Aug 2022 04:02:09
  filedescriptors              1760 [0.0% of 9223372036854775807 limit]
  data collected               Mon, 01 Aug 2022 04:34:49

Conclusion

Congratulations! You have successfully installed and configured the Monit monitoring tool on Ubuntu 22.04. You can now explore the Monit features, add more services, and monitor them via a web browser. Feel free to ask me if you have any questions.