WRT Router Series Monit: Difference between revisions

 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
This subject could apply to installations on other platforms besides OpenWRT.
This subject could apply to installations on other platforms besides OpenWRT.


Monit allow for monitoring (via command line or web GUI) of services, plus restarting of services if they're not running or not responding.
Monit allow for monitoring (via command line or web GUI (http://WhatEverIPAddressOrHostName:2812 (default port))) of services, plus restarting of services if they're not running or not responding.


===Installation===
===Installation===
Line 8: Line 8:
opkg install monit
opkg install monit


===Configuration File(s) for Monit Service===
===Configuration File(s) & Directories for Monit Service===
/etc/monitrc
/etc/monitrc (file)
 
/etc/monit.d (directory)


If configuring in a fashion similar to operating systems such as CentOS, then;
If configuring in a fashion similar to operating systems such as CentOS, then;
Line 30: Line 32:
</syntaxhighlight>
</syntaxhighlight>


=== Configuration of Individual Service(s) Monitoring ===
===Configuration of Individual Service(s) Monitoring===
If configured in the manner described in the Configuration File(s) for Monit Service section, each of the following example can be placed in a separate text file in the /etc/monit.d directory.
If configured in the manner described in the Configuration File(s) for Monit Service section, each of the following example can be placed in a separate text file in the /etc/monit.d directory.


Apache Example;<syntaxhighlight lang="text">
Apache Example (The below Apache example is very simple.  It can also be configured to connect to a website and check for the existence of a specific file);
<syntaxhighlight lang="text">
check process httpd with pidfile /tmp/run/apache2/httpd.pid
check process httpd with pidfile /tmp/run/apache2/httpd.pid
start program "/etc/init.d/apache2 start"
start program "/etc/init.d/apache2 start"
Line 39: Line 42:
restart program "/etc/init.d/apache2 restart"
restart program "/etc/init.d/apache2 restart"
if 5 restarts within 5 cycles then timeout
if 5 restarts within 5 cycles then timeout
</syntaxhighlight>BIND / NAMED Example;
</syntaxhighlight>
BIND / NAMED Example;
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
check process named with pidfile /tmp/run/named/named.pid
start program "/etc/init.d/named start"
stop program "/etc/init.d/named stop"
restart program "/etc/init.d/named restart"
if failed host 192.168.2.1 port 53 type tcp protocol dns then restart
if failed host 192.168.2.1 port 53 type udp protocol dns then restart
if 5 restarts within 5 cycles then timeout
</syntaxhighlight>
DHCPC Example;
check process dhcpd with pidfile /tmp/run/dhcpd.pid
start program "/etc/init.d/dhcpd start"
stop program "/etc/init.d/dhcpd stop"
restart program "/etc/init.d/dhcpd restart"
if failed host 192.168.2.1 port 67 type udp then restart
if 5 restarts within 5 cycles then timeout
<nowiki></syntaxhighlight></nowiki>
MySQL Example;
<syntaxhighlight lang="text">
check process mysqld with pidfile /tmp/run/mysqld/mysqld.pid
start program "/etc/init.d/mysqld start"
stop program "/etc/init.d/mysqld stop"
restart program "/etc/init.d/mysqld restart"
if failed unixsocket /tmp/run/mysqld/mysqld.sock then restart
if 5 restarts within 5 cycles then timeout
</syntaxhighlight>


DHCPC Example
===Notifications & Alerts===
The Monit service can also send email notifications and alerts.  This can get annoying over time, but it is useful if troubleshooting or monitoring a process.  The annoyance can also be "reigned in" to a certain degree.
 
===Some Interesting HDD / SSD Monitoring Tips===
From: https://www.smarthomebeginner.com/monit-monitor-hard-drive-smart-health-and-temperature/
 
And to monitor via UUID instead of "SDx" (which is a bit unreliable): https://wiki.archlinux.org/index.php/S.M.A.R.T.


MySQL Example
===Additional Tips===
For monitoring OpenVPN: https://serverfault.com/questions/647506/make-monit-check-openvpn-client-connection-status


===Notifications & Alerts===
===Finally / Lastly===
The Monit service can also send email notifications and alerts. This can get annoying over time, but it is useful if troubleshooting or monitoring a process. The annoyance can also be "reigned in" to a certain degree.
Access Monit here (assuming it is set to it's default port and not using HTTPS): http://WhatEverIpAddressOfRouter:2812
 
...and of course after configuring a new MONIT file, restart the service: service monit restart
 
===Credits & Thanks===
A lot of information from here (not sure if this is the original source, but crediting just the same): https://www.smarthomebeginner.com/monit-monitor-file-server-status-samba-nfs/