Système de graph pour le monitoring

Un article de Casys (Canadian Sysadmins).


Auteur: Thomas Boutry

Sommaire

Configuration de NagiosGraph dans nagios

Je n'utiliserai pas le package nagiosgrapher disponible avec Ubuntu, j'utiliserai nagiosgraph.

Installation

téléchargement du produit sur le site : http://nagiosgraph.wiki.sourceforge.net/ La version installée pour cette documentation est 0.9 .

Vérification des packages pré-requis:

 dpkg -l | egrep -i 'rrdtool|perl-base|nagios2 '

Création d'un répertoire pour les fichiers web de nagiosgraph et copies des fichiers web
dans le répertoires

sudo mkdir /usr/share/nagios2/htdocs/nagiosgraph
sudo cp insert.pl show.cgi /usr/share/nagios2/htdocs/nagiosgraph/

Modification du fichier de configuration de insert.pl

sudo vi /usr/local/nagiosgraph/bin/insert.pl
---
#my $configfile = '/usr/local/etc/nagiosgraph/nagiosgraph.conf';
my $configfile = '/usr/local/nagiosgraph/etc/nagiosgraph.conf';
---

Même chose pour show.pl et insert.pl dans le répertoire /usr/share/nagios2/nagiosgraph/

Création du répertoire pour l'application nagiograph, copie des fichiers de configuration
et d'application.

sudo mkdir -p /usr/local/nagiosgraph/etc/ /usr/local/nagiosgraph/bin
sudo cp nagiosgraph.conf /usr/local/nagiosgraph/etc/
sudo cp map  /usr/local/nagiosgraph/etc/
sudo cp insert.pl /usr/local/nagiosgraph/bin/

Création du répertoire de log pour nagiosgraph

sudo mkdir /var/log/nagiosgraph
sudo chown nagios.nagios /var/log/nagiosgraph

Création du répertoire de stockage des fichiers de graphique:

sudo mkdir /usr/local/nagiosgraph/rrd/
sudo chown nagios.nagios /usr/local/nagiosgraph/rrd/

Configuration de l'applications

Nagiosgraph

Réalisation du fichier de configuration de nagiosgraph :

sudo vi /usr/local/nagiosgraph/etc/nagiosgraph.conf 
---
# Debug levels
# 0 = None
# 1 = Critical
# 2 = Error
# 3 = Warn
# 4 = Info
# 5 = Debug
debug = 2

# Location of debug log file
logfile = /var/log/nagios2/nagiosgraph.log

# Directory to store rrd database files
rrddir =  /usr/local/nagiosgraph/rrd

# File containing regular expressions to identify service and perf data
mapfile = /usr/local/nagiosgraph/map

# Color scheme for graphs. Choose a number between 1 and 8.
colorscheme = 1

# Heartbeat. In seconds, twice the size of servicecheck intervals
heartbeat = 600

# Location of performance data log file. Comment out it not used.
perflog = /var/log/nagios2/perfdata.log

# Stylesheet - added to head of show.cgi. Comment out if not used
stylesheet = /nagios/stylesheets/nagiosgraph.css

# RRAs resolution (optional, don't touch if you don't know what you are doing)
#resolution = 17280 17520 32850 1095

# Organization of rrd files
# _ = single character separator for all files in same dir
# subdir = files in subdirectory structure with "___" separator
dbseparator = subdir

# Plot form (LINE1..LINE3, AREA, TICK)
plotas = LINE2

# Graphs to show in every page (day, week, month, quarter, year)
# time = day week month year

---

Ajout de la configuration pour la réalisation des graphes d'espace disque :

sudo vi /usr/local/nagiosgraph/etc/map
---
# Service check Disk space snmp
# Output :      /: 6%used(2948MB/47309MB) (<90%) : OK  or
# Output :      /home: 2%used(6971MB/410738MB) (<90%) : OK
/output:.*(\/[a-zA-Z]*):.*\((\d+)MB.*/
and push @s, [ $1,
               [ 'size',  GAUGE, $2 ]];
---

Ajoput de la configuration pour la réalisation du graph pour le load:

sudo vi /usr/local/nagiosgraph/etc/map
---
# Insert here a map entry to parse the nagios plugin data above.
# Output :      Load : 0.27 0.22 0.18 : OK
#   perfdata:load1=0;15;30;0 load5=0;10;25;0 load15=0;5;20;0
/output:.*Load : (\d+\.\d+) (\d+\.\d+) (\d+\.\d+).*/
and push @s, [ 'Load_average',
             [ 'avg1min',  GAUGE, $1 ],
             [ 'avg5min',  GAUGE, $2 ],
             [ 'avg15min',  GAUGE, $3 ]];
---

J'ai du mettre des ' sur toutes les entrés example :

# Service type: unix-www <br>
#   ouput:HTTP OK HTTP/1.1 200 OK - 1456 bytes in 0.003 seconds <br>
/output:HTTP.*?(\d+) byte.*?([.0-9]+) sec/ <br>
and push @s, [ 'http', <br>
               [ 'bps', GAUGE, $1/$2 ] ]; <br>

Nagios

Configuration du fichiers nagios :

sudo vi /etc/nagios2/nagios.cfg
---
process_performance_data=1
service_perfdata_file=/var/log/nagios2/perfdata.log
# Add for nagiosgraph
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
# add for nagiosgraph
service_perfdata_file_mode=a
# Add for nagiosgraph
service_perfdata_file_processing_interval=30
# Add nagiosgraph
service_perfdata_file_processing_command=process-service-perfdata
sudo vi /etc/nagios2/command.cfg
---
define command {
     command_name  process-service-perfdata
     command_line  /usr/local/nagiosgraph/bin/insert.pl
}
---

Ajout du lien vers nagiosgraph dans l'interface nagios

sudo vi /etc/nagios2/conf.d/extinfo_nagios2.cfg
---
define serviceextinfo {
    service_description  PING
    host_name       gateway
    notes_url       /nagiosgraph/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
    icon_image      graph.gif
    icon_image_alt  View graphs
}


define serviceextinfo {
    service_description  Total Process
    hostgroup_name   Unix
    notes_url       /nagiosgraph/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
    icon_image      graph.gif
    icon_image_alt  View graphs
}

define serviceextinfo {
    service_description  Zombies Process
    hostgroup_name   Unix
    notes_url       /nagiosgraph/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
    icon_image      graph.gif
    icon_image_alt  View graphs
}

define serviceextinfo {
    service_description  Disk Space /home
    hostgroup_name   Unix
    notes_url       /nagiosgraph/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&fixedscale
    icon_image      graph.gif
    icon_image_alt  View graphs
}


define serviceextinfo {
    service_description  Disk Space /
    hostgroup_name   Unix
    notes_url       /nagiosgraph/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&fixedscale
    icon_image      graph.gif
    icon_image_alt  View graphs
}

define serviceextinfo {
    service_description  Load Average
    hostgroup_name   Unix
    notes_url       /nagiosgraph/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&fixedscale
    icon_image      graph.gif
    icon_image_alt  View graphs
}


---

Validez la configuration de nagios et redemarrer le service

sudo nagios2 -v /etc/nagios2/nagios.cfg
sudo /etc/init.d/nagios2 restart

Le fichier graph.gif n'est pas disponible par default avec nagios , il faut donc en trouvé un autre sur internet
Je vous invite a chercher sur google.com

cd /usr/share/nagios2/htdocs/images/logos/
sudo wget  www.un_site_web.com/graph.gif

Logrotate

Ajout de la rotation des logues :


sudo vi /etc/logrotate.d/nagios2-common
---
/var/log/nagios2/*.log {
        weekly
        missingok
        rotate 4
        compress
        delaycompress
        notifempty
        create 640 nagios nagios
        sharedscripts
        postrotate
                if [ -f /var/run/nagios2/nagios2.pid ]; then
                        /etc/init.d/nagios2 reload > /dev/null
                fi
        endscript
}

Apache

Configuration de apache pour l'interface web de nagiosgraph

sudo vi /etc/apache2/conf.d/nagios2.conf
---
ScriptAlias /nagiosgraph/ /usr/share/nagios2/htdocs/nagiosgraph/
---

check de configuration et redémarrer apache

sudo apache2ctl configtest
sudo /etc/init.d/apache2 restart

Modification des permissions pour que l'application de graph web puisse ouvrir le fichier de log

chmod o+r /var/log/nagios2/

Référence

Site web du site nagiosGraph : http://nagiosgraph.wiki.sourceforge.net/