483 lines
14 KiB
Markdown
483 lines
14 KiB
Markdown
---
|
||
categories: web
|
||
title: Howto Munin.
|
||
...
|
||
|
||
* [Documentation générale](http://munin-monitoring.org/wiki/Documentation)
|
||
* [Détails sur les légendes](http://demo.munin-monitoring.org/munin-monitoring.org/demo.munin-monitoring.org/)
|
||
|
||
## Installation
|
||
|
||
~~~
|
||
# aptitude install munin
|
||
~~~
|
||
|
||
Munin ajoute un cron, qui s'exécute toutes les 5 minutes, il se situe dans `/etc/cron.d`.
|
||
|
||
## Configuration
|
||
|
||
### Configuration générale
|
||
|
||
Le fichier `/etc/munin/munin.conf` permet de configurer Munin. Par défaut les graphs sont générés dans `/var/cache/munin/www`, on peut soit le changer, soit faire un lien symbolique dans `/var/www`.
|
||
|
||
Changer le nom d'hôte :
|
||
|
||
~~~
|
||
# a simple host tree
|
||
[monserveur.mondomaine.com]
|
||
address 127.0.0.1
|
||
use_node_name yes
|
||
~~~
|
||
|
||
Il sera peut-être nécéssaire d'éditer le fichier `/etc/munin/munin-node.conf` pour y autoriser une machine à récupérer les informations, par exemple :
|
||
|
||
~~~
|
||
allow ^127\.0\.0\.1$
|
||
allow ^X\.Y\.Z\.W$
|
||
~~~
|
||
|
||
> Ne pas oublier d'autoriser l'IP X.Y.Z.W à joindre le serveur via le port 4949.
|
||
|
||
## Fonctionnement
|
||
|
||
Toutes les 5 minutes, munin va aller interroger ses "nodes" listés dans munin.conf (par défaut uniquement localhost.localdomain).
|
||
Il va ainsi mettre à jour ses fichiers RRD stockés dans `/var/lib/munin` puis générer des graphiques (images PNG) à partir des fichiers RRD.
|
||
Ces graphiques PNG, stockés dans `/var/cache/munin` se retrouveront affichés dans des pages HTML, également générées.
|
||
|
||
### Fichiers RRD
|
||
|
||
Les fichiers RRD sont les données les plus importantes, ils stockent en effet toutes les valeurs du passé.
|
||
|
||
À chaque plugin est associé un ou plusieurs fichiers RRD.
|
||
|
||
~~~
|
||
$ ls *load-*
|
||
localhost.localdomain-load-load-g.rrd
|
||
$ ls *cpu-*
|
||
localhost.localdomain-cpu-idle-d.rrd localhost.localdomain-cpu-iowait-d.rrd localhost.localdomain-cpu-irq-d.rrd localhost.localdomain-cpu-nice-d.rrd
|
||
localhost.localdomain-cpu-softirq-d.rrd localhost.localdomain-cpu-steal-d.rrd localhost.localdomain-cpu-system-d.rrd localhost.localdomain-cpu-user-d.rrd
|
||
~~~
|
||
|
||
Si vous n'avez que les fichiers RRD (cas d'une sauvegarde par exemple), vous pouvez recréer des graphes via _rrdtool_.
|
||
Voici un exemple pour tracer un graphe de load sur un intervalle passé :
|
||
|
||
~~~
|
||
$ rrdtool graph foo.png -a PNG --start -15d --end -4d --width 800 --height 800 'DEF:load=localhost.localdomain-load-load-g.rrd:42:AVERAGE' 'LINE1:load#ff0000:Load' -l 0 -u 1
|
||
~~~
|
||
|
||
## Ajouter un noeud
|
||
|
||
Commençons par autoriser les connections avec le master (31.120.1.12) depuis la machine cliente (31.120.1.13) :
|
||
|
||
~~~
|
||
echo "allow ^31\.120\.1\.12$" >> /etc/munin/munin-node.conf
|
||
/etc/init.d/minifirewall restart
|
||
~~~
|
||
|
||
Il reste plus qu'a indiquer la machine sur master
|
||
|
||
|
||
~~~
|
||
vim /etc/munin/munin-node.conf ; /etc/init.d/minifirewall restart
|
||
~~~
|
||
|
||
Et ajouter ces directives :
|
||
|
||
~~~
|
||
[client.foo.com]
|
||
address 31.120.1.13
|
||
use_node_name yes
|
||
~~~
|
||
|
||
|
||
|
||
## Munin 2
|
||
|
||
Munin 2 permet enfin de zoomer sur les graphiques !
|
||
|
||
Pour que cela fonctionne il faut faire tourner un démon FastCGI et le script munin-cgi-graph.
|
||
|
||
### Intégration avec Nginx
|
||
|
||
Adapter les droits de `/var/log/munin/munin-cgi` :
|
||
|
||
~~~
|
||
# chown www-data:munin /var/log/munin/munin-cgi-*
|
||
# chmod 660 /var/log/munin/munin-cgi-*
|
||
~~~
|
||
|
||
De même pour `/etc/logrotate.d/munin`, section `/var/log/munin/munin-cgi-graph.log` :
|
||
|
||
~~~
|
||
create 660 www-data munin
|
||
~~~
|
||
|
||
Démarrer le démon FastCGI avec `spawn-fcgi` (`apt install libcgi-fast-perl spawn-fcgi`) :
|
||
|
||
~~~
|
||
spawn-fcgi -s /var/run/munin/spawn-fcgi-munin-graph.sock -U www-data -u munin -g munin /usr/lib/munin/cgi/munin-cgi-graph
|
||
~~~
|
||
|
||
Si spawn-fcgi ne démarre pas mais renvoie `spawn-fcgi: child exited with: 2`, il se peut que ce soit car le paquet **libcgi-fast-perl** manque
|
||
|
||
|
||
On le mettra dans `/etc/rc.local` pour le lancer au démarrage de la machine (un script d'init bien fait est disponible sur <http://files.julienschmidt.com/public/cfg/munin/spawn-fcgi-munin-graph>
|
||
|
||
En Debian 8 on pourra créer une unité systemd :
|
||
|
||
~~~{.ini}
|
||
[Unit]
|
||
Description=Munin zoom for nginx.
|
||
After=network.target
|
||
|
||
[Service]
|
||
ExecStart=/usr/bin/spawn-fcgi -s /var/run/munin/spawn-fcgi-munin-graph.sock -U www-data -u munin -g munin /usr/lib/munin/cgi/munin-cgi-graph
|
||
Type=forking
|
||
|
||
[Install]
|
||
WantedBy=default.target
|
||
~~~
|
||
|
||
|
||
Enfin dans le vhost concerné d'Nginx, ajoutez-ceci :
|
||
|
||
~~~{.nginx}
|
||
location /munin/ {
|
||
alias /var/cache/munin/www/;
|
||
}
|
||
|
||
location ^~ /munin-cgi/munin-cgi-graph/ {
|
||
fastcgi_split_path_info ^(/munin-cgi/munin-cgi-graph)(.*);
|
||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||
fastcgi_pass unix:/var/run/munin/spawn-fcgi-munin-graph.sock;
|
||
include fastcgi_params;
|
||
}
|
||
~~~
|
||
|
||
### Avec Apache
|
||
|
||
Installer `libapache2-mod-fcgid` puis ajouter au vhost :
|
||
|
||
~~~{.apache}
|
||
# Munin cgi
|
||
# Ensure we can run (fast)cgi scripts
|
||
ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
|
||
<Location /munin-cgi/munin-cgi-graph>
|
||
Options +ExecCGI
|
||
<IfModule mod_fcgid.c>
|
||
SetHandler fcgid-script
|
||
</IfModule>
|
||
<IfModule mod_fastcgi.c>
|
||
SetHandler fastcgi-script
|
||
</IfModule>
|
||
<IfModule !mod_fastcgi.c>
|
||
<IfModule !mod_fcgid.c>
|
||
SetHandler cgi-script
|
||
</IfModule>
|
||
</IfModule>
|
||
Allow from all
|
||
</Location>
|
||
~~~
|
||
|
||
## Notifications
|
||
|
||
Munin est capable d'envoyer des mails quand un plugin atteint son seuil de warning ou critical. Toute la configuration se fait dans `munin.conf`, on indique un mail de contact, et éventuellement on ajuste les seuils (ou on les définit) d'un ou plusieurs plugins.
|
||
|
||
Exemple :
|
||
|
||
~~~
|
||
contact.someuser.command mail -s "Munin notification" foo@example.com
|
||
|
||
[example.foo.bar]
|
||
address 127.0.0.1
|
||
use_node_name yes
|
||
postfix_mailqueue.deferred.critical 200
|
||
~~~
|
||
|
||
On peut aussi configuré les seuils de warning ou critical dans le fichier de configuration `/etc/munin/plugin-conf.d/munin-node`, voici un exemple de seuils sur le check du retard sur la réplication mysql :
|
||
|
||
~~~
|
||
[mysql*]
|
||
user root
|
||
env.mysqlopts --defaults-file=/etc/mysql/debian.cnf
|
||
env.mysqluser debian-sys-maint
|
||
env.mysqlconnection DBI:mysql:mysql;mysql_read_default_file=/etc/mysql/debian.cnf
|
||
env.seconds_behind_master_warning 120
|
||
env.seconds_behind_master_critical 800
|
||
~~~
|
||
|
||
## Plugins
|
||
|
||
Les plugins sont stockés dans `/usr/share/munin/plugins`.
|
||
Les plugins activés sont mis en place via un lien symbolique dans `/etc/munin/plugins/`.
|
||
|
||
Exemple :
|
||
|
||
~~~
|
||
$ ls -lha /etc/munin/plugins/
|
||
[…]
|
||
lrwxrwxrwx 1 root root 40 3 juin 10:31 apache_accesses -> /usr/share/munin/plugins/apache_accesses
|
||
[…]
|
||
~~~
|
||
|
||
Pour ajouter un plugin à grapher il suffit donc de mettre en place un lien symbolique.
|
||
Il faut ensuite redémarrer munin-node : `/etc/init.d/munin-node restart`
|
||
|
||
### Tester un plugin
|
||
|
||
Il peut être utile, et recommandé de tester le plugin avant de le mettre en place, pour cela il faut utiliser l'outil `munin-run --debug nom_du_plugin`.
|
||
|
||
Exemple :
|
||
|
||
~~~
|
||
$ munin-run --debug swap
|
||
# Processing plugin configuration from /etc/munin/plugin-conf.d/munin-node
|
||
# Set /rgid/ruid/egid/euid/ to /111/65534/111 111 /65534/
|
||
# Setting up environment
|
||
# About to run '/etc/munin/plugins/swap'
|
||
swap_in.value 19
|
||
swap_out.value 53
|
||
~~~
|
||
|
||
### Configurer le user/group d'un plugin
|
||
|
||
Selon les besoins, il peut être utile d'exécuter un plugin avec un utilisateur et un groupe particuliers.
|
||
Pour cela il faut éditer le fichier `/etc/munin/plugin-conf.d/munin-node` et changer le user/group.
|
||
|
||
Exemple :
|
||
|
||
~~~
|
||
[munin_stats]
|
||
user munin
|
||
group munin
|
||
~~~
|
||
|
||
## Utiliser plusieurs fois un plugin
|
||
|
||
Il est possible d'utiliser plusieurs fois un même plugin mais avec des paramètres différents. C'est très utile pour le plugin MySQL par exemple.
|
||
|
||
~~~
|
||
/etc/munin/plugins# for type in bytes queries slowqueries threads; do for instance in 3307 3309; do ln -s /usr/share/munin/plugins/mysql_${type} mysql_${instance}_${type}; done; done
|
||
/etc/munin/plugins# ls -lha mysql_330*
|
||
lrwxrwxrwx 1 root root 36 Jul 22 11:23 mysql_3307_bytes -> /usr/share/munin/plugins/mysql_bytes
|
||
lrwxrwxrwx 1 root root 38 Jul 22 11:23 mysql_3307_queries -> /usr/share/munin/plugins/mysql_queries
|
||
lrwxrwxrwx 1 root root 42 Jul 22 11:23 mysql_3307_slowqueries -> /usr/share/munin/plugins/mysql_slowqueries
|
||
lrwxrwxrwx 1 root root 38 Jul 22 11:23 mysql_3307_threads -> /usr/share/munin/plugins/mysql_threads
|
||
lrwxrwxrwx 1 root root 36 Jul 22 11:23 mysql_3309_bytes -> /usr/share/munin/plugins/mysql_bytes
|
||
lrwxrwxrwx 1 root root 38 Jul 22 11:23 mysql_3309_queries -> /usr/share/munin/plugins/mysql_queries
|
||
lrwxrwxrwx 1 root root 42 Jul 22 11:23 mysql_3309_slowqueries -> /usr/share/munin/plugins/mysql_slowqueries
|
||
lrwxrwxrwx 1 root root 38 Jul 22 11:23 mysql_3309_threads -> /usr/share/munin/plugins/mysql_threads
|
||
~~~
|
||
|
||
Puis dans le fichier /etc/munin/plugin-conf.d/mysql_multi :
|
||
|
||
~~~
|
||
[mysql_3307_*]
|
||
user root
|
||
env.mysqlopts --defaults-extra-file=/etc/mysql/debian.cnf -h127.0.0.1 -P3307
|
||
|
||
[mysql_3309_*]
|
||
user root
|
||
env.mysqlopts --defaults-extra-file=/etc/mysql/debian.cnf -h127.0.0.1 -P3309
|
||
~~~
|
||
|
||
|
||
## Le plugin postgresql
|
||
|
||
Installer `libdbd-pg-perl`
|
||
|
||
~~~
|
||
# aptitude install libdbd-pg-perl
|
||
~~~
|
||
|
||
Linker les plugins généraux :
|
||
|
||
~~~
|
||
ln -s /usr/share/munin/plugins/postgres_bgwriter /etc/munin/plugins/
|
||
ln -s /usr/share/munin/plugins/postgres_checkpoints /etc/munin/plugins/
|
||
ln -s /usr/share/munin/plugins/postgres_connections_db /etc/munin/plugins/
|
||
ln -s /usr/share/munin/plugins/postgres_users /etc/munin/plugins/
|
||
ln -s /usr/share/munin/plugins/postgres_xlog /etc/munin/plugins/
|
||
~~~
|
||
|
||
Pour les plugins wildcard finissant par _ ajoutez `ALL` pour monitorer toutes les BDD :
|
||
|
||
~~~
|
||
ln -s /usr/share/munin/plugins/postgres_cache_ /etc/munin/plugins/postgres_cache_ALL
|
||
ln -s /usr/share/munin/plugins/postgres_connections_ /etc/munin/plugins/postgres_connections_ALL
|
||
ln -s /usr/share/munin/plugins/postgres_locks_ /etc/munin/plugins/postgres_locks_ALL
|
||
ln -s /usr/share/munin/plugins/postgres_querylength_ /etc/munin/plugins/postgres_querylength_ALL
|
||
ln -s /usr/share/munin/plugins/postgres_size_ /etc/munin/plugins/postgres_size_ALL
|
||
ln -s /usr/share/munin/plugins/postgres_transactions_ /etc/munin/plugins/postgres_transactions_ALL
|
||
~~~
|
||
|
||
sauf les suivants qui ne peuvent analyser qu'une seule base de données :
|
||
|
||
~~~
|
||
ln -s /usr/share/munin/plugins/postgres_scans_ /etc/munin/plugins/postgres_scans_NOMBDD
|
||
ln -s /usr/share/munin/plugins/postgres_tuples_ /etc/munin/plugins/postgres_tuples_NOMBDD
|
||
~~~
|
||
|
||
Attention avec **Squeeze LTS**, la version du serveur contient lts (ex: PostgreSQL 8.4.22lts5) et le plugin ne fonctionne plus.
|
||
Il faut modifier le fichier `/usr/share/perl5/Munin/Plugin/Pgsql.pm` et remplacer la ligne :
|
||
|
||
~~~
|
||
unless ($v =~ /^PostgreSQL (\d+)\.(\d+)\.(\d+) on/);
|
||
~~~
|
||
|
||
par :
|
||
|
||
~~~
|
||
unless ($v =~ /^PostgreSQL (\d+)\.(\d+)\.(\d+)lts(\d) on/);
|
||
~~~
|
||
|
||
### Le plugin dnsresponsetime
|
||
|
||
Il faut éditer le fichier `/etc/munin/plugin-conf.d/munin-node` et ajouter la section du plugin pour spécifier un nom à résoudre et un ou des serveurs DNS :
|
||
|
||
~~~
|
||
[dnsresponsetime]
|
||
env.queries evolix.fr@ns2.evolix.net evolix.fr@romario.evolix.net
|
||
~~~
|
||
|
||
### Le plugin bind_rndc
|
||
|
||
Ajouter les lignes suivante dans `/etc/munin/plugin-conf.d/munin-node` :
|
||
|
||
~~~
|
||
[bind9_rndc]
|
||
user root
|
||
env.querystats /var/chroot-bind/var/cache/bind/named.stats
|
||
~~~
|
||
|
||
Assurez-vous d'avoir configuré le fichier `named.stats`, voir [HowtoBind#Graphsdesstatsviarndc].
|
||
|
||
### Le plugin bind
|
||
|
||
Assurez-vous d'avoir configurer un « channel de log » pour les requêtes DNS. Cf. [HowtoBind#Graphsdesacc%C3%A8sviaunfichierdelog].
|
||
|
||
Ajouter les lignes suivante dans `/etc/munin/plugin-conf.d/munin-node`
|
||
|
||
~~~
|
||
[bind9]
|
||
user root
|
||
env.logfile /var/chroot-bind/var/log/queries.log
|
||
~~~
|
||
|
||
Attention au chemin si bind est chrooté !
|
||
|
||
Un bug nécessite de créer le fichier des infos munin à la main…
|
||
|
||
~~~
|
||
# cd /var/lib/munin/plugin-state/
|
||
# touch bind9.state
|
||
# chown munin:munin bind9.state
|
||
# chmod 664 bind9.state
|
||
~~~
|
||
|
||
### Le plugin tomcat
|
||
|
||
~~~
|
||
# ln -s /usr/share/munin/plugins/tomcat_ tomcat_jvm
|
||
# ln -s /usr/share/munin/plugins/tomcat_ tomcat_threads
|
||
# ln -s /usr/share/munin/plugins/tomcat_ tomcat_volume
|
||
# ln -s /usr/share/munin/plugins/tomcat_ tomcat_access
|
||
# ln -s /usr/share/munin/plugins/tomcat_ tomcat_avgtime
|
||
# ln -s /usr/share/munin/plugins/tomcat_ tomcat_maxtime
|
||
~~~
|
||
|
||
~~~
|
||
[tomcat_*]
|
||
env.host 127.0.0.1
|
||
env.port 8080
|
||
env.request /manager/status?XML=true
|
||
env.user admin
|
||
env.password mon_pass
|
||
env.timeout 30
|
||
~~~
|
||
|
||
### Le plugin squid
|
||
|
||
~~~
|
||
ln -s /usr/share/munin/plugins/squid_cache /etc/munin/plugins/
|
||
ln -s /usr/share/munin/plugins/squid_icp /etc/munin/plugins/
|
||
ln -s /usr/share/munin/plugins/squid_objectsize /etc/munin/plugins/
|
||
ln -s /usr/share/munin/plugins/squid_requests /etc/munin/plugins/
|
||
ln -s /usr/share/munin/plugins/squid_traffic /etc/munin/plugins/
|
||
~~~
|
||
|
||
Ajuster le port si nécessaire :
|
||
|
||
~~~
|
||
[squid*]
|
||
env.squidhost 127.0.0.1
|
||
env.squidport 80
|
||
~~~
|
||
|
||
S'assurer que les directives suivantes sont bien présentes dans `/etc/squid3/squid.conf` :
|
||
|
||
~~~
|
||
# munin
|
||
acl manager proto cache_object
|
||
<http_access> allow manager localhost
|
||
<http_access> deny manager
|
||
~~~
|
||
|
||
Vérification :
|
||
|
||
~~~
|
||
squidclient -p 80 cache_object://127.0.0.1/storedir
|
||
squidclient -p 80 cache_object://127.0.0.1/server_list
|
||
squidclient -p 80 cache_object://127.0.0.1/info
|
||
squidclient -p 80 cache_object://127.0.0.1/counters
|
||
~~~
|
||
|
||
## Débug
|
||
|
||
Soucis droits sur images. Si munin n'affice pas les images, c'est peut-être un souci de droits. Vérifier les droits dans `/var/cache/munin/www/*/*/`. Si les .png sont en 600, faire ceci :
|
||
|
||
~~~
|
||
# echo "umask 022" >> /etc/default/cron
|
||
# /etc/init.d/cron restart
|
||
# chmod 644 /var/cache/munin/www/*/*/*.png
|
||
~~~
|
||
|
||
On peut lancer la generation des graphs à la main pour avoir des informations plus précises :
|
||
|
||
~~~
|
||
su - munin --shell=/bin/bash
|
||
/usr/share/munin/munin-update --debug
|
||
~~~
|
||
|
||
|
||
### Tester le plugin
|
||
|
||
~~~
|
||
$ munin-run -d <plugin> #présent dans /etc/munin/plugins/
|
||
~~~
|
||
|
||
### Problème de graph, munin ne graphe plus
|
||
|
||
Vérifier la conf du plugin qui ne graphe pas, dans /etc/munin/plugin-conf.d/munin-node
|
||
|
||
Il faut regarder si la variable env.url a bien le nom du serveur en
|
||
question et pas 127.0.0.1. Par exemple avec le plugin apache :
|
||
|
||
~~~
|
||
[apache_*]
|
||
env.url http://nomduserveur.evolix.net:%d/server-status-XXXXX?auto
|
||
env.ports 8080
|
||
~~~
|
||
|
||
On peut aussi vérifier que la requête vers l'url fonctionne en faisant un GET vers l'url:
|
||
|
||
~~~
|
||
GET http://nomduserveur.evolix.net:8080/server-status-XXXXX?auto
|
||
~~~
|
||
|
||
### Regarder dans la doc
|
||
|
||
~~~
|
||
$ munindoc <plugin>
|
||
~~~
|