Informations :
Dates
- Publish : : Monday 01 march 2010
- Modification : Thursday 01 september 2011
- 8477 views
Share :
Le but est bien entendu de rendre accessible ces graphiques depuis l'extérieur en utilisant un serveur web, comme Apache, ce qui permet de surveiller l'activité de l'ordinateur à distance, depuis un simple navigateur web.
Il faut dans un premier temps installer SNMP (Simple Network Management Protocol). Il s'agit d'un outil qui permet aux administrateurs réseau de gérer les équipements réseau et de diagnostiquer les problèmes de réseau, en local ou à distance.
Puis nous installerons MRTG (Multi Routeur Traffic Graph) pour lire et générer les graphs.
SNMP : Simple Network Management Protocol
Installer SNMP
Script avec 2 lignes
001aptitude update002aptitude install snmp
Editer le fichier /etc/snmp/snmpd.conf
Script avec 1 ligne
001vi /etc/snmp/snmpd.conf
Script avec 2 lignes
001#com2sec paranoid default public002com2sec readonly default public
puis redémarer le service
Script avec 1 ligne
001/etc/init.d/snmpd restart
MRTG : Multi Routeur Traffic Graph
Installer MRTG
Script avec 1 ligne
001aptitude install mrtg
Créer le fichier de configuration par défaut de MRTG
Script avec 1 ligne
001cfgmaker public@127.0.0.1 --global 'Language: French' > /etc/mrtg.cfg
Parcourir le fichier /etc/mrtg.conf (je vous ai mis quelques options avec commentaire)
Script avec 1 ligne
001cat /etc/mrtg.conf
Script avec 61 lignes
001#######################002# Global Settings003RunAsDaemon: yes004 005# Répertoire de destination des graphes, des fichiers de données (log,old), des pages html.006WorkDir:/var/www/mrtg/007 008# On peut choisir le chemin où doit se trouver les fichiers html, png, log.009Htmldir: /var/www/mrtg/010Imagedir: /var/www/mrtg/images011Logdir: /var/www/mrtg/logs012 013# Options générales014# growright, noinfo, transparent, unknaszero, bits, nopercent, growright, gauge015# défilement de droite à gauche, fond des graphes transparent, en cas de problème de poling le graphe tombe à zéro sinon MRTG prend la dernière valeur connnue et trace une ligne continue tant que MRTG n'arrive plus interroger l€€€équipement.016Options[_]:growright,transparent,unknaszero017 018# Cela permet de supprimer les graphes voulus (y=yearly m=monthly w=weekly d=daily).019Suppress[_]: y020 021#######################022# Cible : interface:communauté@IP023# Target correspond à ce que nous voulons interroger.024Target[string]: 1:Public@127.0.0.1025 026# Options correspond aux options spécifiques du graphe et annule la ou les options générales spécifiées lors de la création du fichier de configuration.027Options[string]: growleft, nobanner, noinfo028 029# Title correspond au titre de la page html générée.030Title[string]: Titre du graph031 032# Normalement MRTG ajuste automatiquement la valeur maximale du graphe pour avoir la meilleure échelle possible.033# Cette option permet en fait d'annuler cet automatisme et d'avoir un graphe fixe.034Unscaled[string]: dwym035 036# Fixe la valeur maximale des graphes, cette valeur est en octets.037MaxBytes[string]: 1250000038 039AbsMax[string]: 1250000040 041# Si vous voulez monter plus de 4 lignes par graphique.042Ytics[string]: 6043 044# Cela permet d'ajuster les graphes, c'est à dire cela consiste à multiplier le graphe par une valeur.045YScale[string]: 1.25046XScale[string]: 1.5047 048# Permet de mettre une légende explicite à l'axe des y.049YLegend[string]: Packets /s050 051# Cela consiste à définir la taille du graphe en pixel de 20 à 600 par axe.052YSize[string]: 150053XSize[string]: 600054 055Legend1[string]: IN Packets /s056Legend2[string]: OUT Packets /s057LegendI[string]: IN P/s:058LegendO[string]: OUT P/s:059 060# Légende des valeurs des graphes.061ShortLegend[string]: P/s
Tester la génération des graphs
Script avec 1 ligne
001indexmaker --output /var/www/mrtg/index.html /etc/mrtg.cfg --nolegend
Ajouter à la crontab
Script avec 1 ligne
001crontab -e
Script avec 1 ligne
0010,5,10,15,20,25,30,35,40,45,50,55 * * * * indexmaker --output /var/www/mrtg/index.html /etc/mrtg.cfg --nolegend 2>/dev/null 2>&1
Graphique sur les paquets reçus et envoyés
Créer le fichier de conf qui va bien /etc/mrtg/packets-in-out.cfg
Script avec 1 ligne
001vi /etc/mrtg/packets-in-out.cfg
Script avec 16 lignes
001#----------------eth0---------------002WorkDir: /var/www/mrtg003Target[eth0]: `perl -e '@a=split(/[:s]+/,qx(grep eth0 /proc/net/dev));printf "%.0fn%.0fn1neth0 trafficn",$a[2],$a[10];'`;004Options[eth0]: dorelpercent, growright, nobanner, noinfo, transparent005MaxBytes[eth0]: 2000000006AbsMax[eth0]: 10000000007kilo[eth0]: 1024008YLegend[eth0]: Bytes per second009ShortLegend[eth0]: B/s010Legend1[eth0]: Incoming Traffic in Bytes per second011Legend2[eth0]: Outgoing Traffic in Bytes per second012LegendI[eth0]: In:013LegendO[eth0]: Out:014Title[eth0]: Traffic Analysis for : eth0015PageTop[eth0]: <h1>Traffic Analysis for : eth0</h1>016#----------------end eth0---------------
Temps de latence
Il faut dans un premier temps faire un p'tit script /etc/mrtg/pinghost.sh
Script avec 1 ligne
001vi /etc/mrtg/pinghost.sh
Script avec 6 lignes
001#!/bin/sh002P=`ping -c3 -q $1|grep avg|cut -d" " -f4`003MIN=`echo $P|cut -d"/" -f1`004MAX=`echo $P|cut -d"/" -f2`005echo $MAX006echo $MIN
On passe au fichier les droits d'execution pour l'utilisateur
Script avec 1 ligne
001chmod u+x /etc/mrtg/pinghost.sh
On peut maintenant y faire appel depuis MRTG
Créer le fichier de conf qui va bien /etc/mrtg/pinghost.cfg
Script avec 1 ligne
001vi /etc/mrtg/pinghost.cfg
Script avec 18 lignes
001#---------Ping HOSTEUR--------------------002WorkDir: /var/www/mrtg003Target[ping_zw3b]: `/etc/mrtg/pinghost.sh 217.16.4.49`004Options[ping_zw3b]: nopercent,growright,gauge,noinfo, nobanner005MaxBytes[ping_zw3b]: 10000006AbsMax[ping_zw3b]: 10000007YLegend[ping_zw3b]: Latence008ShortLegend[ping_zw3b]: ms009Legend1[ping_zw3b]: Latence max en ms010Legend2[ping_zw3b]: Latence min en ms011LegendI[ping_zw3b]: Latence Max:012LegendO[ping_zw3b]: Latence Min:013Title[ping_zw3b]: Ping sur www.zw3b.fr014PageTop[ping_zw3b]: <h1>Latence www.zw3b.fr</h1>015WithPeak[ping_zw3b]:wmy016Legend4[ping_zw3b]: Max de la latence min017Legend3[ping_zw3b]: Max de la latence max018#--------end ping-----------------------------
CPU
Créer le fichier de conf qui va bien /etc/mrtg/cpu.cfg
Script avec 1 ligne
001vi /etc/mrtg/cpu.cfg
Script avec 18 lignes
001WorkDir: /var/www/mrtg002LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt003Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@127.0.0.1+ ssCpuRawSystem.0&ssCpuRawSystem.0:public@127.0.0.1+004ssCpuRawNice.0&ssCpuRawNice.0:public@127.0.0.1005RouterUptime[localhost.cpu]: public@127.0.0.1006MaxBytes[localhost.cpu]: 100007Title[localhost.cpu]: CPU Load008PageTop[localhost.cpu]: Active CPU Load %009Unscaled[localhost.cpu]: ymwd010ShortLegend[localhost.cpu]: %011YLegend[localhost.cpu]: CPU Utilization012Legend1[localhost.cpu]: Active CPU in % (Load)013Legend2[localhost.cpu]:014Legend3[localhost.cpu]:015Legend4[localhost.cpu]:016LegendI[localhost.cpu]: Active017LegendO[localhost.cpu]:018Options[localhost.cpu]: growright,nopercent
Memory Usage
Créer le fichier de conf qui va bien /etc/mrtg/mem.cfg
Script avec 1 ligne
001vi /etc/mrtg/mem.cfg
Script avec 13 lignes
001LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt002Target[localhost.mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost003PageTop[localhost.mem]:Free Memory004WorkDir: /var/www/mrtg005Options[localhost.mem]: nopercent,growright,gauge,noinfo006Title[localhost.mem]: Free Memory007MaxBytes[localhost.mem]: 1000000008kMG[localhost.mem]: k,M,G,T,P,X009YLegend[localhost.mem]: bytes010ShortLegend[localhost.mem]: bytes011LegendI[localhost.mem]: Free Memory:012LegendO[localhost.mem]:013Legend1[localhost.mem]: Free memory, not including swap, in bytes
Memory Monitoring (Total Versus Available Memory)
Créer le fichier de conf qui va bien /etc/mrtg/memfree.cfg
Script avec 1 ligne
001vi /etc/mrtg/memfree.cfg
Script avec 13 lignes
001LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt002Target[server.memory]: memAvailReal.0&memTotalReal.0:public@localhost003Title[server.memory]: Free Memory004PageTop[server.memory]: < H1 >Free Memory< /H1 >005MaxBytes[server.memory]: 100000000000006ShortLegend[server.memory]: B007YLegend[server.memory]: Bytes008LegendI[server.memory]: Free009LegendO[server.memory]: Total010Legend1[server.memory]: Free memory, not including swap, in bytes011Legend2[server.memory]: Total memory012Options[server.memory]: gauge,growright,nopercent013kMG[server.memory]: k,M,G,T,P,X
Memory Monitoring (Percentage usage)
Créer le fichier de conf qui va bien /etc/mrtg/mempercent.cfg
Script avec 1 ligne
001vi /etc/mrtg/mempercent.cfg
Script avec 13 lignes
001LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt002Title[server.mempercent]: Percentage Free Memory003PageTop[server.mempercent]: < H1 >Percentage Free Memory< /H1 >004Target[server.mempercent]: ( memAvailReal.0&memAvailReal.0:publicy@localhost ) * 100 / ( memTotalReal.0&memTotalReal.0:public@localhost )005options[server.mempercent]: growright,gauge,transparent,nopercent006Unscaled[server.mempercent]: ymwd007MaxBytes[server.mempercent]: 100008YLegend[server.mempercent]: Memory %009ShortLegend[server.mempercent]: Percent010LegendI[server.mempercent]: Free011LegendO[server.mempercent]: Free012Legend1[server.mempercent]: Percentage Free Memory013Legend2[server.mempercent]: Percentage Free Memory
Disk Usage
Créer le fichier de conf qui va bien /etc/mrtg/disk.cfg
Script avec 1 ligne
001vi /etc/mrtg/disk.cfg
Script avec 11 lignes
001LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt002Target[server.disk]: dskPercent.1&dskPercent.2:public@localhost003Title[server.disk]: Disk Partition Usage004PageTop[server.disk]: < H1 >Disk Partition Usage /home and /var< /H1 >005MaxBytes[server.disk]: 100006ShortLegend[server.disk]: %007YLegend[server.disk]: Utilization008LegendI[server.disk]: /home009LegendO[server.disk]: /var010Options[server.disk]: gauge,growright,nopercent011Unscaled[server.disk]: ymwd
Création des tâches à planifiées
Script avec 7 lignes
001echo $'#!/bin/shn/usr/bin/mrtg /etc/mrtg/packets-in-out.cfg' > /etc/cron.mrtg/packets-in-out002echo $'#!/bin/shn/usr/bin/mrtg /etc/mrtg/pinghost.cfg' > /etc/cron.mrtg/pinghost003echo $'#!/bin/shn/usr/bin/mrtg /etc/mrtg/cpu.cfg' > /etc/cron.mrtg/cpu004echo $'#!/bin/shn/usr/bin/mrtg /etc/mrtg/mem.cfg' > /etc/cron.mrtg/mem005echo $'#!/bin/shn/usr/bin/mrtg /etc/mrtg/memfree.cfg' > /etc/cron.mrtg/memfree006echo $'#!/bin/shn/usr/bin/mrtg /etc/mrtg/mempercent.cfg' > /etc/cron.mrtg/mempercent007echo $'#!/bin/shn/usr/bin/mrtg /etc/mrtg/disk.cfg' > /etc/cron.mrtg/disk
Générer les fichiers Index
Script avec 11 lignes
001#/usr/bin/indexmaker --output=/var/www/mrtg/cpu-mem/index.html002--title="Memory and CPU Usage"003--sort=name004--enumerate005/etc/cron.mrtg/cpu006/etc/cron.mrtg/mem007/etc/cron.mrtg/memfree008/etc/cron.mrtg/mempercent009/etc/cron.mrtg/disk010--columns=2011--nolegend
Script avec 8 lignes
001#/usr/bin/indexmaker --output=/var/www/mrtg/networks/index.html002--title="Networks Traffic"003--sort=name004--enumerate005/etc/cron.mrtg//packets-in-out006/etc/cron.mrtg/pinghost007--columns=2008--nolegend
L'option --columns=2 indique qu'on affiche 2 graphiques par ligne
L'option --nolegend indique qu'on affiche pas le bas de page publicitaire de MRTG
Générer le fichier mrtg.cfg
Script avec 4 lignes
001#cfgmaker "global "WorkDir: /var/www/mrtg/"002--global "Options[_]: growright,bits"003--ifref=ip004public@localhost > /etc/mrtg.conf
Ajout de la tache planifiée toutes les 5mn
Script avec 2 lignes
001cat >> /var/spool/cron/crontabs/root002*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null
En bref :
MRTG nous permet de diagnostiquer des équipements réseau afin d'assurer la pérennité d'un réseau, tels que :
- Cpu (Unité de calcul centrale, généralement c'est le processeur principal sur les équipements d'interconnexions et sur les ordinateurs du réseau
- Ram sur routeur et switch
- Fichiers ouverts
- Espace disque
- Requêtes DNS (Domaine)
Il permet de faire de la surveillance sur un réseau afin de créer des statistiques. Un de ses avantages, c'est qu'il est gratuit. Cependant MRTG présente certains inconvénients :
- Création de pages HTML pour chaque interface (inadapté aux grands sites).
- Trop orienté SNMP
- Graphiques à deux courbes
- Pas de gestion des données non fournies
Il existe un autre outil de monitoring réseau appelé RRDTOOL, toujours développé par Tobias Oetiker lancé en 1997. Il présente quelques améliorations par rapport à MRTG :
- Meilleure gestion des archives
- Intégration de mathématiques pour gérer les nombres flottants
- Gestion de plus de deux valeurs (contrairement à MRTG)
- Graphiques provenant de sources multiples
Néanmoins comme avec MRTG, les pages HTML ne sont pas intégrées au logiciel.





