===== Monit ===== [[https://mmonit.com/monit//|Monit]] is a free, simple and effective monitoring tool that can help you keep an eye on your home server and services while also perform actions like restart or stop services if some events happens. It can also monitor your filesystems for overload and free space. Check: [[https://wiki.gentoo.org/wiki/Monit|Gentoo Wiki Monit]] page for specific Gentoo suggestions, which i will mostly repeat also in this page. ==== Installation ==== First of all, installing //MonIt// is pretty easy: emerge -v monit To start monit, while it is recommended to start monit through the **/etc/inittab** so that init itself launches the monit application, i suggest to put it in //local.d// as the **last** daemon started. This is to prevent Monit to try restart daemons before the full startup sequence is completed. So create **/etc/local.d/99-monit.start**: #!/bin/bash #Start monit last to prevent it from trying to spawn services while local.d is still starting /etc/init.d/monit start And make the script executable. ==== Configuration ==== Monit is configured from it's main config file **/etc/monitrc**. I assume you want your users in the **users** group to be allowed Monit access, and also you want to disable the default admin/monit password. So edit the **/etc/monitrc** file and do the following changes: ... omissis ... 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 # comment this line to disable default user! allow @users # allow members of the //users// group to access Monit ... omissis ... ## It is possible to include additional configuration parts from other files or ## directories. include /etc/monit.d/* # uncomment this line to enable custom configs! ... omissis ... You will place all your custom monitors under **/etc/monit.d/** folder. For example, to monitor your filesystems create the file **/etc/monit.d/filesystems**: check filesystem Data with path /data if space usage > 90% then alert check filesystem Deposito with path /deposito if space usage > 90% then alert check filesystem Root with path / if space usage > 90% then alert And to monitor some services: check process sonarr with pidfile /var/run/sonarr.pid start program = "/bin/bash -c 'rc-service sonarr start'" stop program = "/bin/bash -c 'rc-service sonarr stop'" check process radarr with pidfile /var/run/radarr.pid start program = "/bin/bash -c 'rc-service radarr start'" stop program = "/bin/bash -c 'rc-service radarr stop'" check process readarr with pidfile /var/run/readarr.pid start program = "/bin/bash -c 'rc-service readarr start'" stop program = "/bin/bash -c 'rc-service readarr stop'" check process readarr-audiobooks with pidfile /var/run/readarr-audiobooks.pid start program = "/bin/bash -c 'rc-service readarr-audiobooks start'" stop program = "/bin/bash -c 'rc-service readarr-audiobooks stop'" check process lidarr with pidfile /var/run/lidarr.pid start program = "/bin/bash -c 'rc-service lidarr start'" stop program = "/bin/bash -c 'rc-service lidarr stop'" check process prowlarr with pidfile /var/run/prowlarr.pid start program = "/bin/bash -c 'rc-service prowlarr start'" stop program = "/bin/bash -c 'rc-service prowlarr stop'" And to monitor some network links: check network ISP1 with interface enp0s20f0u4u4c2 if link down then alert if changed link then alert check network ISP2 with interface enp59s0u2u4c2 if link down then alert if changed link then alert check network internal with interface enp0s31f6 if link down then alert if changed link then alert Feel free to add/edit as needed. To have monit read the changes, issue the command: monit reload ==== Reverse Proxy ==== Create the following NGINX configuration file: location = /monit { return 301 https://$host/monit/; } location /monit/ { rewrite ^/monit/(.*) /$1 break; proxy_ignore_client_abort on; proxy_pass http://127.0.0.1:2812; proxy_redirect / /monit/; proxy_cookie_path / /monit/; proxy_set_header Host $host; } place it accordingly to [[selfhost:nginx|The Reverse Proxy concept]] and restart NGINX. ==== Start & Test ==== Now start it manually, no need to reboot the server for this: /etc/init.d/monit start Open your browser and head to **https://10.0.0.1/monit** to login with your user credentials (or a user in the //users// group!)