Tag: monit

  • Install Monit on CentOS

    Monit allow you to monitor process. It can restart failed process or alert when server is overloaded.

    On CentOS server, you need to enable EPEL repo to install monit.

    yum install epel-release -y
    

    Install monit with

    yum install monit -y
    

    Enable monit to auto start on boot

    systemctl enable monit
    

    Start monit service

    systemctl start monit
    

    On CentOS, monit configuration file located at

    vi  /etc/monitrc
    

    See monit

  • Monitor OpenLiteSpeed with monit

    OpenLiteSpeed Monit

    To monitor OpenLiteSpeed with monit on Ubuntu Server, create file

    vi /etc/monit/conf-enabled/openlitespeed
    

    Add following content

    check process OpenLiteSpeed with pidfile /tmp/lshttpd/lshttpd.pid
        start program = "/usr/bin/systemctl start lshttpd"
        stop program = "/usr/bin/systemctl stop lshttpd"
    

    Reload monit with

    monit reload
    

    Now monit will monitor OpenLiteSpeed, restart if required. You can check status with

    monit status
    

    monit status openlitespeed

    If you want to monitor if web server is responding to request, you can use

    check process OpenLiteSpeed with pidfile /tmp/lshttpd/lshttpd.pid
        start program = "/usr/bin/systemctl start lshttpd"
        stop program = "/usr/bin/systemctl stop lshttpd"
        if failed host localhost port 80 protocol http then restart
    
  • gonit golang replacement for monit

    gonit is a replacent for monitoring software monit. monit was removed from Debian 10 due to security issues and the devloper will not provide a patch for the security vlunerabilty in time for Debian 10 release.

    You can download gonit from

    https://github.com/bitnami/gonit

    root@ip-172-26-14-184:~# gonit status
    
    Uptime                         22h5m41s
    Last Check                     2019-08-05 08:23:57.612314368 +0000 UTC m=+79440.116643915
    Next Check                     2019-08-05 08:25:57.612314368 +0000 UTC m=+79560.116643915
    Pid                            3162
    Pid File                       /var/run/gonit.pid
    Control File                   /etc/gonit/gonitrc
    Socket File                    /var/run/gonit.sock
    Log File                       /var/log/gonit.log
    Process 'apache'
      status                                        Running
      pid                                              2020
      uptime                                       22h5m41s
      monitoring status                           monitored
    
    Process 'mysql'
      status                                        Running
      pid                                              1911
      uptime                                       22h5m41s
      monitoring status                           monitored
    
    Process 'php-fpm'
      status                                        Running
      pid                                              2014
      uptime                                       22h5m41s
      monitoring status                           monitored
    
    
    root@ip-172-26-14-184:~# 
    
  • Install Monit on Ubuntu

    Install Monit on Ubuntu

    Monit can be used to monitor services, restart them if required. To install monit, run

    apt -y install monit
    

    To start monit, run

    systemctl start monit
    

    Monitor Apache

    vi /etc/monit/conf-available/apache2-custom
    

    Add

    check process apache with pidfile /var/run/apache2/apache2.pid
        group www-data
        start program = "/etc/init.d/apache2 start"
        stop program  = "/etc/init.d/apache2 stop"
        if failed host localhost port 80 protocol http then restart
        if 5 restarts within 5 cycles then timeout
    

    Activate the rule with

    ln -s /etc/monit/conf-available/apache2-custom /etc/monit/conf-enabled/apache2-custom
    

    Restart monit with

    systemctl restart monit
    

    Testing If Monit works

    Open 2 terminals. On one, tail the monit logs with

    tail -f /var/log/monit.log
    

    On other terminal, stop Apache

    service apache2 stop
    

    Within 2 minutes, monit will restart apache web server.

    monit

  • monit

    See gonit golang replacement for monit

    monit is a process monitoring service that monitor services, restart if required.

    https://mmonit.com/monit/

    Install monit

    monit configuration

    Here are monit rules used to monitor apache, php-fpm and MySQL on bitnami cloud server.

    # cat apache.conf
    check process apache
      with pidfile "/opt/bitnami/apache2/logs/httpd.pid"
      start program = "/opt/bitnami/apache2/scripts/ctl.sh start" with timeout 90 seconds
      stop program = "/opt/bitnami/apache2/scripts/ctl.sh stop" with timeout 90 seconds
    
    # cat php-fpm.conf
    check process php-fpm
      with pidfile "/opt/bitnami/php/var/run/php5-fpm.pid"
      start program = "/opt/bitnami/php/scripts/ctl.sh start" with timeout 90 seconds
      stop program = "/opt/bitnami/php/scripts/ctl.sh stop" with timeout 90 seconds
    
    # cat mysql.conf
    check process mysql
      with pidfile "/opt/bitnami/mysql/data/mysqld.pid"
      start program = "/opt/bitnami/mysql/scripts/ctl.sh start" with timeout 90 seconds
      stop program = "/opt/bitnami/mysql/scripts/ctl.sh stop" with timeout 90 seconds
    
    #
    

    monitor php-fpm

    check process php7-fpm with pidfile "/var/run/php/php7.0-fpm.pid"
        if cpu > 80% for 2 cycles then alert