Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Monitoring Tools»How To Install and Configure Monit on Linux

    How To Install and Configure Monit on Linux

    By RahulJune 26, 20174 Mins Read

    Monit, A Process and Services Monitoring Tool is a small Open Source utility for monitoring and managing Unix like systems. Monit monitors the server programs to increase services uptime and ensures that they stay online consistently.

    Advertisement

    This article will help you to install and configure Monit on CentOS, RHEL, Fedora, Ubuntu, Dabian and Scientific Linux. Monit has capability to monitory any of services running on system, We just only need to add settings in it. In this article we will only show you configuration for few services only.

    Step 1 – Install Monit

    Monit can be easily installed with package manager in most of Linux flavors. For CentOS/RHEL users need to enable epel repository in his system before installing it.

    CentOS, RHEL and Scientific Linux

    # yum install monit
    

    Fedora 22+

    # dnf install monit
    

    Debian and Ubuntu

    $ sudo apt-get install monit
    

    Arch Linux

    $ pacman -S monit
    

    Step 2 – Enable Monit Web Interface

    (Optional For CLI Lovers) Monit also provided an web interface to view services and processes status. To enable monit web interface, edit configuration file ( For RHEL based /etc/monit.conf & For Dabian Based System /etc/monit/monitrc ) in your favorite editor and uncomment following lines

    set httpd port 2812 and
        use address localhost
        allow localhost
        allow admin:monit
        allow @monit
        allow @users readonly
    

    and start monit service.

    # service monit start
    
    Starting monit: monit: generated unique Monit id 0dbd9dc3f0aa7ed7df9e7a069aea9b84 and stored to '/root/.monit.id'  [  OK  ]
    

    As per above configuration monit will start on port 2812 and only accessible from localhost. To change default port simply update first line of above showing configuration and set your preferred port.

    Now access Monit web interface by pointing your browser to 2812 on localhost

    monit-installation-1

    Step 3 – Monitor Apache Service with Monit

    Let’s start with adding services in Monit to monitor them and take necessary action on condition meet. The very first service we are adding Apache. Edit your monit configuration file and add following settings at end of file

    On CentOS, RHEL: /etc/monit.conf

    check process apache with pidfile /var/run/httpd.pid
        start program = "/etc/init.d/httpd start" with timeout 60 seconds
        stop program  = "/etc/init.d/httpd stop"
    

    On Dabian/Ubuntu: /etc/monit/monitrc

    check process apache with pidfile /run/apache2.pid
        start program = "/etc/init.d/apache2 start" with timeout 60 seconds
        stop program  = "/etc/init.d/apache2 stop"
    

    Now restart monit service using service monit restart and check the status of service using command line.

    # monit summary
    
    The Monit daemon 5.1.1 uptime: 2m
    
    Process 'apache'                    running
    System 'svr1.tecadmin.net'          running
    

    Step 4 – Configure Monit To Monitor MySQL/MariaDB

    Let’s add MySQL server in Monit configuration file to monitor it. PID file location and init script may change as per your MySQL version installed.

    check process mysqld with pidfile /var/run/mysqld/mysqld.pid
        start program = "/etc/init.d/mysql start"
        stop program = "/etc/init.d/mysql stop"
    

    To Read more about monit configuration exmaples visit http://mmonit.com/wiki/Monit/ConfigurationExamples

    Step 5 – Verify Configuration and Test

    After adding required services in monit monitoring configuration file, Use the below command to verify syntax of file

    # monit -t
    

    Now restart monit service

    # service monit restart
    

    Now view the summary of monitoring processes and services by Monit.

    # monit summary
    
    The Monit daemon 5.1.1 uptime: 0m
    
    Process 'apache'                    running
    Process 'mysqld'                    running
    System 'svr1.tecadmin.net'          running
    

    To view detailed description of each service use the following command

    # monit status
    

    [Sample Output]

    The Monit daemon 5.1.1 uptime: 1m
    
    Process 'apache'
      status                            running
      monitoring status                 monitored
      pid                               16206
      parent pid                        1
      uptime                            13m
      children                          10
      memory kilobytes                  10432
      memory kilobytes total            65100
      memory percent                    1.3%
      memory percent total              8.3%
      cpu percent                       0.0%
      cpu percent total                 0.0%
      data collected                    Tue Apr 29 03:49:13 2014
    
    Process 'mysqld'
      status                            running
      monitoring status                 monitored
      pid                               1962
      parent pid                        1867
      uptime                            10h 38m
      children                          0
      memory kilobytes                  60568
      memory kilobytes total            60568
      memory percent                    7.7%
      memory percent total              7.7%
      cpu percent                       0.0%
      cpu percent total                 0.0%
      data collected                    Tue Apr 29 03:49:13 2014
    
    System 'svr1.tecadmin.net'
      status                            running
      monitoring status                 monitored
      load average                      [0.00] [0.07] [0.08]
      cpu                               0.2%us 0.1%sy 0.2%wa
      memory usage                      518444 kB [66.7%]
      data collected                    Tue Apr 29 03:49:13 2014
    
    

    Also we can show the status of processes and services on Monit web interface

    monit-process-monitoring

    monit monitoring Monitoring Tool processes
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Bash Script to Monitor Disk Space and Notify

    Shell Script to Monitor Disk Space and Send Alert

    How to Install Nagios Client (NRPE) on Ubuntu 20.04

    Installing Nagios on Ubuntu

    How to Install Nagios Server on Ubuntu 20.04

    View 3 Comments

    3 Comments

    1. arun kumar on September 23, 2021 7:24 am

      Hi Team

      i understand how to install, configure and monitor programs and processes in the local system. but i am unable to find the solution to monitor remote Virtual machines.

      Can you please explain the process of monitoring the remote VM’s using monit tool.

      Reply
    2. SG on February 27, 2018 9:56 am

      Hey man, this one really helped me, thanks a lot!

      Reply
    3. Danila on September 18, 2014 8:05 pm

      Hi Rahul! Nice write up covering many distributions. If anyone is interested on getting the latest version of Monit without adding additional repositories on CentOS 6, here is a quick guide: http://www.getpagespeed.com/server-setup/monit-on-centos-6

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.