Monit – A Open Source Tool for Managing and Monitoring Linux System

Monit is a free open source and very useful tool that automatically monitors and manages processes, files, directories, checksums, permissions, filesystems, and services like Apache, Nginx, MySQL, FTP, SSH, SMTP, and so on in a UNIX/Linux based systems and provides an excellent and helpful monitoring functionality to system administrators.

The monit has a user-friendly web interface where you can directly view the system status and setup up processes using a native HTTP(S) web server or via the command line interface. This means you must have web server like Apache or Nginx installed on your system to access and view the monit web interface.

[ You might also like: 20 Command Line Tools to Monitor Linux Performance ]

What Monit Can Do

Monit has the ability to start a process if it is not running, restart a process if not responding, and stop a process if uses high resources. Additionally, you can also use Monit to monitor files, directories, and filesystems for changes, checksum changes, file size changes, or timestamp changes.

With Monit, you can able to monitor remote hosts’ TCP/IP port, server protocols, and ping. Monit keeps its own log file and alerts about any critical error conditions and recovery status.

This article is written to describe a simple guide on Monit installation and configuration on RHEL-based and Debian-based Linux distributions.

Step 1: Installing Monit in Linux

By default, the Monit monitoring program is not available from the default system base repositories, you need to add and enable a third-party epel repository to install the monit package under RHEL-based distributions such as CentOS, Rocky Linux, and AlmaLinux.

--------- On RHEL 9 based Systems --------- 
# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm 

--------- On RHEL 8 based Systems --------- 
# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

--------- On RHEL 7 based Systems ---------
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Once you’ve added the epel repository, install the Monit package by running the following yum command.

# yum install monit
OR
# dnf install monit  [On Fedora Linux]
Install Monit in RHEL
Install Monit in RHEL

For Ubuntu/Debian/Linux Mint user’s can easily install using the apt command as shown.

$ sudo apt install monit

Step 2: Configuring Monit in Linux

Monit is very easy to configure, in fact, the configuration files are created to be very easily readable and making them easier for users to understand. It is designed to monitor the running services every 2 minutes and keeps the logs in “/var/log/monit“.

Monit has a web interface that runs on port 2812 using a web server. To enable the web interface you need to make changes in the monit configuration file.

The main configuration file of monit located at /etc/monit.conf under (RedHat/CentOS/Fedora) and /etc/monit/monitrc file for (Ubuntu/Debian/Linux Mint).

Open this file using your choice of editor.

# vi /etc/monitrc
Or
$ sudo nano /etc/monit/monitrc

Next, uncomment the following section and add the IP address or domain name of your server, allow anyone to connect and change the monit user and password or you can use default ones.

set httpd port 2812 and
     use address 0.0.0.0  # only accept connections from localhost
     allow 0.0.0.0/0        # allow localhost to connect to the server and
     allow admin:monit      # require user 'admin' with password 'monit'
     allow @monit           # allow users of group 'monit' to connect (rw)
     allow @users readonly  # allow users of group 'users' to connect readonly
Configure Monit in Linux
Configure Monit in Linux

Once you’ve configured it, you need to start, enable and verify the monit service to reload the new configuration settings.

# systemctl start monit
# systemctl enable monit
# systemctl status monit
Start Monit in RHEL
Start Monit in RHEL

Now, you will be able to access the monit web interface by navigating to the following URLs.

http://localhost:2812
OR
http://ip-address:2812
Or
http://example.com:2812

Then enter the user name as “admin” and password as “monit“. You should get a screen similar to the one below.

Monit Login
Monit Login
Monit Service Manager
Monit Service Manager
Monit System Status
Monit System Status

Step 3: Adding Linux Services to Monit Monitoring

Once the monit web interfaces are correctly set up, start adding the programs that you want to monitor into the /etc/monitrc under (RedHat/CentOS/Fedora) and /etc/monit/monitrc file for (Ubuntu/Debian/Linux Mint) at the bottom.

Following are some useful configuration examples for monit, which can be very helpful to see how a service is running, where it keeps its profile, how to start and stop a service, etc.

Monitor Apache in Monit

check process httpd with pidfile /var/run/httpd.pid
group apache
start program = "/usr/bin/systemctl httpd start"
stop program = "/usr/bin/systemctl httpd stop"
if failed host 127.0.0.1 port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout

Monitor Apache2 in Monit

check process apache with pidfile /run/apache2.pid
start program = "/usr/bin/systemctl apache2 start" with timeout 60 seconds
stop program  = "/usr/bin/systemctl apache2 stop"

Monitor Nginx in Monit

check process nginx with pidfile /var/run/nginx.pid
start program = "/usr/bin/systemctl nginx start"
stop program = "/usr/bin/systemctl nginx stop"

Monitor MySQL in Monit

check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group mysql
start program = "/usr/bin/systemctl mysqld start"
stop program = "/usr/bin/systemctl mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

Monitor SSH in Monit

check process sshd with pidfile /var/run/sshd.pid
start program "/usr/bin/systemctl sshd start"
stop program "/usr/bin/systemctl sshd stop"
if failed host 127.0.0.1 port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

Once you’ve configured all programs for monitoring, check monit syntax for errors. If found any errors fix them, it’s not so tough to figure out what went wrong. When you get a message like “Control file syntax OK“, or if you see no errors, you can proceed ahead.

# monit -t
Or
$ sudo monit -t

After fixing all possible errors, you can type the following command to start the monit service.

# systemctl monit restart
OR
$ sudo systemctl monit restart

This is how looks monit after adding all Linux services for monitoring.

Linux Monitoring Services with Monit
Linux Monitoring Services with Monit

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

49 Comments

Leave a Reply
  1. Is it possible to collect telemetry data through Monit? I mean to know whether Monit can be used as a replacement for Opentelemetry.

    Reply
  2. Yes, to monitor multiple hosts from a single dashboard you need to install M-monit, an enterprise application, with a one-time license fee (it is not expensive).

    We use Mmonit at my work to monitor over 100 hosts, has email and slack notifications and metric charts, an excellent monitoring tool that’s much easier to set up and maintain than Nagios.

    Reply
  3. Very helpful documentation on monit. I have a problem sending email alerts for events/service changes and I am getting the error message in the apigee-monit.log –

    [EST Feb 22 23:34:38] error : Mail: STARTTLS required but the mail server doesn’t support it
    Alert handler failed, retry scheduled for next cycle.

    How can I work around this error ?

    # vi /opt/apigee/data/apigee-monit/my-mail-config.conf
    
    SET MAILSERVER  x.com PORT 25
    USERNAME "[email protected]"  PASSWORD ""
    
    # USING SSL, WITH TIMEOUT 30  SECONDS
      USING TLS
    SET MAIL-FORMAT {
      from: [email protected]
      subject: Monit Alert -- Service: $SERVICE $EVENT on $HOST
    }
    SET ALERT [email protected]
    
    Reply
  4. This tutorial is very good. I’m using Debian8, Nginx and ISPConfig. The article does not cite whether it needs or works with Apache or Nginx. So, will it work to monitor any service, either one or the other, and the rest, correct?

    Reply
  5. Not able to install the monit package.. can you please help?
    Last login: Wed Apr 20 14:00:19 2016 from 192.168.124.1
    [root@www ~]# yum install monit -y
    Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    Local-Repo | 2.9 kB 00:00
    Setting up Install Process
    No package monit available.
    Error: Nothing to do
    [root@www ~]# yum install monit* -y –nogpgcheck
    Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    Setting up Install Process
    No package monit* available.
    Error: Nothing to do
    [root@www ~]# rpm -q monit*
    package monit* is not installed
    [root@www ~]# rpm -ivh monit*
    error: File not found by glob: monit*
    [root@www ~]#
    [root@www ~]#
    [root@www ~]#
    [root@www ~]# yum –enablerepo=epel install monit
    Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    [root@www ~]# yum –enablerepo=epel install monit -y –nogpgcheck
    Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

    Reply
  6. I am looking for a tool that lists/logs all “read / write / sent / received” activities of any process in detail additionally.
    Is that possible with this tool?

    It would also be nice to restrict a critical process instead of deleting it like security tools like to do. I am also looking for a tool that monitors installation activities and maybe backups modified system values or at least let me know. Could anyone give me an advisement?

    Reply
    • I need also be sure about any access for example keyboard and mouse or other peripherals. Those psycho attacks are state of the art and there is no easy way to get sure about it so far or I just haven t found the right tool yet.
      I will have a look if anyone has a suggestion for me later on. Thanks for reading :)

      Reply
  7. Is monit able to monitor logging of services?

    For instance, if a service hangs (stops logging) but the process is still running so it still has a pid. Will it be able to monitor that and force a kill on the pid and initiate a restart?

    Reply
    • @Stefan,
      It’s just a monitoring tool that monitors and alerts about the services which are in critical state, it doesn’t take any actions like you saying, you’ve to kill and restart manually..

      Reply
  8. Hi Ravi,

    Thx for this post. It really helps. i’m using Ubuntu 12.10 server, and i was wondering if it should be “mysql” instead of “mysqld” on the third and fourth row for the MySql monitoring services :

    check process mysqld with pidfile /var/run/mysqld/mysqld.pid
    group mysql
    start program = “/etc/init.d/mysqld start”
    stop program = “/etc/init.d/mysqld stop”
    if failed host 127.0.0.1 port 3306 then restart
    if 5 restarts within 5 cycles then timeout

    Because when i use “mysqld” an error occur.

    thx a lot

    Reply
  9. I am unable to access the webUI page and the message I am getting is “The connection was interrupted”and firewall is disabled already. below is my configuration:

    set httpd port 2812 and
    use address 172.16.172.200 # only accept connection from localhost
    allow 172.16.172.200 # allow localhost to connect to the server and
    allow admin:monit # require user ‘admin’ with password ‘monit’
    allow @monit # allow users of group ‘monit’ to connect (rw)
    allow @users readonly # allow users of group ‘users’ to connect readonly

    Any help would be appreciated

    Reply
  10. Very nice. I’m quite new to linux and this tutorial got me through the basics without getting bogged down in all the different things that you can use monit for.
    I appreciated you specifying the commands for the different linux versions. Often tutorials on websites assume you are using a certain flavor of linux, but never mention what that flavor is.

    Reply
  11. how to install it on server i have logged into my server using ssh, installed the monit , the monit status command showing everything fine in the ssh console,but i am unable to access the web panel from browser as http://www.abasc.com:2812 nothing happes just keep on loading

    Reply
  12. i monitored all services using monit tool except
    tomcat server i create tomcat as service also but process Id not created how to monitor tomcat using monit tool this is i am using tomcat script

    #!/bin/bash
    # description: Tomcat Start Stop Restart
    # processname: tomcat
    # chkconfig: 234 20 80
    JAVA_HOME=/usr/sunjdk/jdk1.7.0_25
    PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
    export JAVA_HOME
    export PATH
    CATALINA_HOME=/tomcat-7.0.27/

    case $1 in
    start)
    sh /tomcat-home/bin/startup.sh
    ;;
    stop)
    sh /tomcat-home/bin/shutdown.sh
    ;;
    restart)
    sh /tomcat-home/bin/shutdown.sh
    sh /tomcat-home/bin/startup.sh
    ;;
    esac
    exit 0

    please guide me

    Reply
  13. Hi,

    I have issue with my monit configuration. When I include specific file to include in the monitrc file it does not start but if I include the fulle directory like “include /etc/monit.d/*”. It work perfectly.

    Pleass advise.

    Thanks.

    Reply
  14. Hi,

    I have an issue to access monit GUI after start the monit service.

    In monit.conf i keep the config file as default

    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’
    allow @monit # allow users of group ‘monit’ to connect (rw)
    allow @users readonly # allow users of group ‘users’ to connect readonly

    And try to access using server ip i.e: 10.1.30.3:2812 but the page is unable to connect

    In /var/log/monit it shows denied connection from non-authorized client

    Do u have any idea on above issue?

    Ur help is highly appreciated

    Reply
  15. Can you give me the code to monitor MySQL on another computer on the same network?
    I am using this code:

    check host remote with address 192.168.0.187
    if failed icmp type echo count 3 with timeout 3 seconds then alert
    if failed port 3306 protocol mysql with timeout 15 seconds then alert

    But, connection failed. It says “cannot open connection to INET via TCP.” What to do?

    Reply
    • The code is already given above, just replace IP there and make sure port 3306 is opened on that remote machine.

      Reply
    • Yes! you can monitor bunch of server by simply creating each block for each service, like this.

      check host example.com with address
      172.16.25.125
      if failed port 80 protocol httpd with timeout 15 seconds
      then exec "/usr/bin/ssh [email protected] /etc/init.d/httpd restart"
      
      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.