WRT Router Series Monit

Revision as of 13:24, 31 December 2020 by Root (talk | contribs)

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.

Installation

opkg update

opkg install monit

Configuration File(s) for Monit Service

/etc/monitrc

If configuring in a fashion similar to operating systems such as CentOS, then;

  • Create this Directory: /etc/monit.d
  • Add this line or un-comment this line from /etc/monitrc: include /etc/monit.d/*
  • Add additional configuration files to the /etc/monit.d Directory

Configuration

The default configuration for Monit from OpenWRT is configured in a very secure, with limited capability to view information (IE, it's only available from the command line, see the below configuration section from /etc/monitrc);

set httpd port 2812 and
    use address localhost  # only accept connection from localhost (drop if you use M/Monit)
    allow localhost        # allow localhost to connect to the server and
    allow admin:monit      # require user 'admin' with password 'monit'

The above configuration does not allow for remote viewing via a web browser. But the below configuration allows for a reasonably secure configuration for viewing via a web browser (not including HTTPS, since it is a Local Area Network)

set httpd port 2812 and
    use address W.X.Y.Z     # IP Address that the Monit Web Services "listens" on
    allow W.X.Y.0/24        # IP Address Range that the Monit Web Service allows connections from
    allow WhatEverUserName:WhatEverPassword

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.

Apache Example;

check process httpd with pidfile /tmp/run/apache2/httpd.pid
start program "/etc/init.d/apache2 start"
stop program "/etc/init.d/apache2 stop"
restart program "/etc/init.d/apache2 restart"
if 5 restarts within 5 cycles then timeout

BIND / NAMED Example;

<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

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 </syntaxhighlight> MySQL Example;

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

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.