Monit is not limited to Monitor Linux system performance, also doing auto repair action for dead services
Monit is a small Open Source utility for managing and monitoring Unix system services such as (Apache, MariaDB, FTP, SSH, Sendmail, DNS, etc,.,), programs, files, File systems and directories. Also monitor general system resources on localhost, like CPU usage, Memory and Load Average. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. All the Linux distributions included Monit on their official repository, so we can easily install using the distribution official packages.
Monit can act if an error situation should occur, e.g.; if Apache is not running, Monit can start Apache again automatically. Also it will automatically stop or restart particular service when it using too much resources on server and send you an alert message.
Monit monitor Files, Dirs and File systems changes, such as time stamps changes, checksum changes or size changes. Monitor network connections to various servers, either on localhost or on remote hosts. TCP, UDP and Unix Domain Sockets are supported. Monit will easily integrate with init, upstart or systemd and can use existing run-level scripts to manage services.
Monit has built-in a lightweight HTTP(S) interface you can use to browse the Monit server and check the status of all monitored services. From the web-interface you can start, stop and restart processes and disable or enable monitoring of services.
1) Install Monit on Linux
We can directly install Monit on Debian based systems (Debian, Ubuntu & Mint) but we have to enable EPEL Repository to install Monit on RPM based system (RHEL & CentOS).
[CentOS/RHEL & Upto Fedora 21] # yum install monit [Fedora 22 & later] # dnf install monit [Debian, Ubuntu & Mint] $ sudo apt-get install monit [suse & openSUSE] # zypper install monit [ArchLinux/Manjaro] # pacman -S monit
2) Configure Monit
In order to use Monit, we need to uncomment the below lines from Monit configuration file. By default Monit monitor all services every
2 minutes which was defined in Monit configuration file. Logs are stored at
/var/log/monit on RPM &
/var/log/monit.log on DEB systems.
- /etc/monit.conf : Monit Configuration file on Fedora/CentOS/RHEL
- /etc/monit/monitrc : Monit Configuration file on Ubuntu/Debian/Mint
- /etc/monit/monitrc : Monit Configuration file on Arch based system
- /etc/monitrc : Monit Configuration file on openSUSE
- 2812 : web interface port number
$ sudo nano /etc/monit.conf 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'
After making above changes, you need to start monit service to take effect on changes.
[Start Monit service on SysVinit] $ sudo service monit start [Start Monit service on systemd] $ sudo systemctl restart monit.service
3) Access Monit Web Interface
Make sure you should have installed apache to access the Monit web interface. Navigate to http://localhost:2812 or http://example.com:2812 or http://IP:2812 and enter user name
admin and password
monit. You will get similar to below screen.
4) Adding services to monit
By default Monit configuration file have some service configuration, just open Monit configuration file
/etc/monit.conf on Fedora/CentOS/RHEL &
/etc/monit/monitrc on Ubuntu/Debian/Mint and navigate to
Services section and uncomment the lines under each service which you are going to monitor, then finally restart. For Configuration Examples visit Monit website. I have added few example here.
Apache on systemd (Manjaro)
check process apache with pidfile /var/run/httpd/httpd.pid start program = "systemctl start httpd.service" with timeout 60 seconds stop program = "systemctl stop httpd.service"
Nginx on systemd
check process nginx with pidfile /var/run/nginx.pid start program = "systemctl start nginx.service" stop program = "systemctl stop nginx.service" group www-data (for ubuntu, debian)
proftpd on SysVinit
check process proftpd with pidfile /var/run/proftpd.pid start program = "/etc/init.d/proftpd start" stop program = "/etc/init.d/proftpd stop" if failed port 21 protocol ftp then restart