User Tools

Site Tools


munin

Munin Monitoring Installation

1.0 --- Prerequisites

Apache is used to show the Munin pages, the apache2 fcgid module is required for the Munin graph zoom feature. I will install apache2 and the libapache2-mod-fcgid module with apt:

sudo apt-get install apache2 libcgi-fast-perl libapache2-mod-fcgid

Enable the fcgid module in apache2:

sudo a2enmod fcgid
sudo systemctl restart apache2

1.1 --- Install Munin

To install Munin with apt, run the commands below:

sudo apt-get install munin munin-node munin-plugins-extra libdbd-pg-perl libwww-perl

When the server is running MySQL/MariaDB, then enable the a few extra Munin plugins to monitor MySQL/MariaDB:

cd /etc/munin/plugins
sudo ln -s /usr/share/munin/plugins/mysql_ mysql_
sudo ln -s /usr/share/munin/plugins/mysql_bytes mysql_bytes
sudo ln -s /usr/share/munin/plugins/mysql_queries mysql_queries
sudo ln -s /usr/share/munin/plugins/mysql_slowqueries mysql_slowqueries
sudo ln -s /usr/share/munin/plugins/mysql_threads mysql_threads

Next, we must edit the Munin configuration file /etc/munin/munin.conf. Uncomment the dbdir, htmldir, logdir, rundir, and tmpldir lines (the default values are fine). We want Munin to use the name rpi.tiger-park.com instead of localhost.localdomain in the HTML output, therefore, we replace localhost.localdomain with rpi.tiger-park.com in the simple host tree section. Without the comments, the changed file looks like this:

sudo nano /etc/munin/munin.conf
# Example configuration file for Munin, generated by 'make build'

# The next three variables specifies where the location of the RRD
# databases, the HTML output, logs and the lock/pid files. They all
# must be writable by the user running munin-cron. They are all
# defaulted to the values you see here.
#
dbdir /var/lib/munin
htmldir /var/cache/munin/www
logdir /var/log/munin
rundir /var/run/munin

# Where to look for the HTML templates
#
tmpldir /etc/munin/templates

# Where to look for the static www files
#
#staticdir /etc/munin/static

# temporary cgi files are here. note that it has to be writable by
# the cgi user (usually nobody or httpd).
#
# cgitmpdir /var/lib/munin/cgi-tmp

# (Exactly one) directory to include all files from.
includedir /etc/munin/munin-conf.d
[...]
# a simple host tree
[rpi.tiger-park.com]
 address 127.0.0.1
 use_node_name yes
[...]

We should find the Apache configuration file for Munin /etc/munin/apache.conf - it defines an alias called munin to munin's HTML output directory /var/cache/munin/www which means we can access munin from all websites on this server by using the relative path /munin (e.g. https://rpi.tiger-park.com/munin). Now we will edit the munin.conf file for Apache to allow access from external IP addresses. Create a backup of the original file:

sudo cp /etc/munin/apache24.conf /etc/munin/apache24.conf_bak

Open the file with an editor:

sudo nano /etc/munin/apache24.conf

The file should look like this:

# Munin configuration for apache2
#
# Apache can serve munin's files that are either statically generated
# (in a cron job) or generated on demand (via cgi).
# The relevant munin settings are "html_strategy" and "graph_strategy".
# The related apache settings can be adjusted at the end of this file.
#
# See /usr/share/doc/munin/README.Debian for details.


# ***** COMMON SETTINGS FOR ALL STRATEGIES *****

ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
Alias /munin/static/ /var/cache/munin/www/static/

<Directory /var/cache/munin/www>
    #Require local
    Require all granted
    Options FollowSymLinks SymLinksIfOwnerMatch
    Options None
</Directory>

<Directory /usr/lib/munin/cgi>
    #Require local
    Require all granted
    Options FollowSymLinks SymLinksIfOwnerMatch
    <IfModule mod_fcgid.c>
        SetHandler fcgid-script
    </IfModule>
    <IfModule !mod_fcgid.c>
        SetHandler cgi-script
    </IfModule>
</Directory>


# ***** SETTINGS FOR CGI/CRON STRATEGIES *****

# pick _one_ of the following lines depending on your "html_strategy"
# html_strategy: cron (default)
Alias /munin /var/cache/munin/www
# html_strategy: cgi (requires the apache module "cgid" or "fcgid")
#ScriptAlias /munin /usr/lib/munin/cgi/munin-cgi-html

Now we link the configuration to Apache directory, and enable the configuration:

sudo ln -s /etc/munin/apache24.conf /etc/apache2/conf-available/munin.conf
sudo a2enconf munin.conf

Restart Apache2 and Munin-node:

sudo systemctl restart apache2
sudo systemctl restart munin-node
sudo systemctl enable munin-node

Now wait a few minutes so that Munin can produce its first output, and then go to https://rpi.tiger-park.com/munin/ in your browser, and you see the first statistics.

1.2 --- Password Protect Munin

Now it is a good idea to password-protect the munin output directory unless you want everybody to be able to see every little statistic about your server. To do this, we must create the password file /etc/munin/munin-htpasswd. We want to login with the username muninadmin, so we do this:

sudo htpasswd -c /etc/munin/munin.htpasswd muninadmin

Enter a password for muninadmin. Then open /etc/munin/apache.conf again:

sudo nano /etc/munin/apache24.conf
[...]
<Directory /var/cache/munin/www>
    #Require local
    #Require all granted
    AuthUserFile /etc/munin/munin.htpasswd
    AuthName "Munin"
    AuthType Basic
    Require valid-user
    Options FollowSymLinks SymLinksIfOwnerMatch
    Options None
</Directory>

<Directory /usr/lib/munin/cgi>
    #Require local
    #Require all granted
    AuthUserFile /etc/munin/munin.htpasswd
    AuthName "Munin"
    AuthType Basic
    Require valid-user
    Options FollowSymLinks SymLinksIfOwnerMatch
    <IfModule mod_fcgid.c>
        SetHandler fcgid-script
    </IfModule>
    <IfModule !mod_fcgid.c>
        SetHandler cgi-script
    </IfModule>
</Directory>
[...]

Then restart Apache2 and Munin-node:

sudo systemctl restart apache2
sudo systemctl restart munin-node

1.3 --- Enable additional modules

The Munin command “munin-node-configure –suggest” can be used to get recommendations for additional Munin modules that can be enabled on the server. Run:

sudo munin-node-configure --suggest

The column “used” shows if a module is enabled, the column “Suggestions” shows if the server runs a service that can be monitored by this module. Create a symlink for the module in /etc/munin/plugins to enable it. For example, here I will enable the apache_* modules:

cd /etc/munin/plugins
sudo ln -s /usr/share/munin/plugins/apache_accesses
sudo ln -s /usr/share/munin/plugins/apache_processes
sudo ln -s /usr/share/munin/plugins/apache_volume

Restart Munin to load the new configuration:

sudo systemctl restart munin-node

2.0 --- Install Munin-node on Host/Client

Install munin-node and munin-plugins-extra:

sudo apt-get install munin-node munin-plugins-extra libdbd-pg-perl libwww-perl

Next we must tell the munin client that our munin server rpi.tiger-park.com with the IP address 118.179.43.233 is allowed to connect to retrieve details from the client. To do this, we open /etc/munin/munin-node.conf and add the line allow ^118\.179\.43\.233$ at the bottom of it. Afterwards, the file should look like this:

sudo nano /etc/munin/munin-node.conf
[...]
allow ^127\.0\.0\.1$
allow ^::1$
allow ^118\.179\.43\.233$

2.1 --- Configure Munin Plugins

The Munin command munin-node-configure –suggest can be used to get recommendations for additional Munin modules that can be enabled on the server. Run:

sudo munin-node-configure --suggest

The column “used” shows if a module is enabled, the column “Suggestions” shows if the server runs a service that can be monitored by this module. Create a symlink for the module in /etc/munin/plugins to enable it. Here we will enable the postgres_* modules:

cd /etc/munin/plugins
sudo ln -s /usr/share/munin/plugins/postgres_autovacuum
sudo ln -s /usr/share/munin/plugins/postgres_bgwriter
sudo ln -s /usr/share/munin/plugins/postgres_cache_
sudo ln -s /usr/share/munin/plugins/postgres_checkpoints
sudo ln -s /usr/share/munin/plugins/postgres_connections_
sudo ln -s /usr/share/munin/plugins/postgres_connections_db
sudo ln -s /usr/share/munin/plugins/postgres_locks_
sudo ln -s /usr/share/munin/plugins/postgres_querylength_
sudo ln -s /usr/share/munin/plugins/postgres_scans_
sudo ln -s /usr/share/munin/plugins/postgres_size_
sudo ln -s /usr/share/munin/plugins/postgres_transactions_
sudo ln -s /usr/share/munin/plugins/postgres_tuples_
sudo ln -s /usr/share/munin/plugins/postgres_users
sudo ln -s /usr/share/munin/plugins/postgres_xlog

Finally start and enable munin-node:

sudo systemctl restart munin-node
sudo systemctl enable munin-node

2.2 --- Configure Munin Server

Now we must tell the munin server that there's another system to monitor (www.palacegroupbd.com with the IP address 13.250.96.39). To do this, we open /etc/munin/munin.conf and add a stanza for www.palacegroupbd.com so that the file looks like this:

sudo nano /etc/munin/munin.conf
[...]
[www.palacegroupbd.com]
    address 13.250.96.39
    use_node_name yes
[...]

Restart munin:

sudo systemctl restart munin

x.x --- References

munin.txt · Last modified: 2019/02/02 18:00 by pi