Graphes MRTG

La mise en place de MRTG est relativement simple nous ne traterons pas ici de de son installation mais juste de l’intégration des scripts afin de générer les graphes.

Le fichier de configuration principale se trouve dans /etc/mrtg.cfg voici le contenu de mon fichier :

 

#---------Ping free cac94-8 -------------------- Target[ping_free]: `/etc/mrtg/ping` Options[ping_free]: nopercent,growright,gauge,noinfo, nobanner MaxBytes[ping_free]: 10000 AbsMax[ping_free]: 10000 YLegend[ping_free]: Latence ShortLegend[ping_free]: ms Legend1[ping_free]: Latence max en ms Legend2[ping_free]: Latence min en ms LegendI[ping_free]: Latence Max: LegendO[ping_free]: Latence Min: Title[ping_free]: Ping sur free.fr PageTop[ping_free]: Latence Free sur Cac 94-8 WithPeak[ping_free]:wmy Legend4[ping_free]: Max de la latence min Legend3[ping_free]: Max de la latence max #--------end ping----------------------------- #---------Memory-------------------- Target[mem]: `/etc/mrtg/mem` Options[mem]: nopercent,growright,gauge,noinfo, nobanner Unscaled[mem]:dwmy MaxBytes[mem]: 261025792 Kilo[mem]:1024 YLegend[mem]: RAM ShortLegend[mem]: o Legend1[mem]: Mémoire libre Legend2[mem]: Mémoire utilisée LegendI[mem]: Mém. Libre: LegendO[mem]: Mém. Utilisée: Title[mem]: Mémoire PageTop[mem]: Mémoire WithPeak[mem]:wmy Legend3[mem]: Mémoire libre max Legend4[mem]: Mémoire utilisée max #--------end Memory----------------------------- #---------CPU------------------- Target[cpu]: `/etc/mrtg/cpu1` Options[cpu]: nopercent,growright,gauge,noinfo, nobanner #Unscaled[cpu]:dwmy MaxBytes[cpu]: 100 YLegend[cpu]: % CPU ShortLegend[cpu]: % CPU Legend1[cpu]: % CPU Utilisateur Legend2[cpu]: % CPU Utilisateur + Système LegendI[cpu]: Utilisateur: LegendO[cpu]: Total: Title[cpu]: CPU PageTop[cpu]: CPU WithPeak[cpu]:wmy Legend3[cpu]: Max % CPU Utilisateur Legend4[cpu]: Max % CPU Utilisateur + Système #--------end CPU----------------------------- #----------------eth0---------------# Target[eth0]: `perl -e '@a=split(/[:\s]+/,qx(grep eth0 /proc/net/dev));printf "%.0f\n%.0f\n1\neth0 traffic\n",$a[2],$a[10];'`; Options[eth0]: dorelpercent, growright, nobanner, noinfo, transparent MaxBytes[eth0]: 2000000 AbsMax[eth0]: 10000000 kilo[eth0]: 1024 YLegend[eth0]: Bytes per second ShortLegend[eth0]: B/s Legend1[eth0]: Incoming Traffic in Bytes per second Legend2[eth0]: Outgoing Traffic in Bytes per second LegendI[eth0]: In: LegendO[eth0]: Out: Title[eth0]: net eth0 traffic PageTop[eth0]: net eth0 traffic #----------------eth1---------------# Target[eth1]: `perl -e '@a=split(/[:\s]+/,qx(grep eth1 /proc/net/dev));printf "%.0f\n%.0f\n1\neth1 traffic\n",$a[2],$a[10];'`; Options[eth1]: dorelpercent, growright, nobanner, noinfo, transparent MaxBytes[eth1]: 2000000 AbsMax[eth1]: 10000000 kilo[eth1]: 1024 YLegend[eth1]: Bytes per second ShortLegend[eth1]: B/s Legend1[eth1]: Incoming Traffic in Bytes per second Legend2[eth1]: Outgoing Traffic in Bytes per second LegendI[eth1]: In: LegendO[eth1]: Out: Title[eth1]: net eth1 traffic PageTop[eth1]: net eth1 traffic

Crée un fichier ping dans /etc/mrtg/

#!/bin/sh P=`ping -w6 -c3 -q 78.254.1.200|grep rtt|cut -d" " -f4` MIN=`echo $P|cut -d"/" -f1` MAX=`echo $P|cut -d"/" -f2` echo $MAX echo $MIN

Crée un fichier mem dans /etc/mrtg/

#!/bin/sh USED=`free -b|grep Mem| cut -d ":" -f2|cut -c16-26` FREE=`free -b|grep Mem| cut -d ":" -f2|cut -c27-37` echo $USED echo $FREE

Crée un fichier cpu1 dans /etc/mrtg/

#!/usr/bin/perl @line = `/usr/bin/sar | grep all | /usr/bin/tail -n 2 | /usr/bin/head -n 1 | /bin/sed 's/\ \ */ /g'`; @data = split(/ /, @line[0]); if (@data[2] eq "") { printf "0\n"; }else { printf ("%3.0f\n", @data[2] + 0.5); } printf ("%3.0f\n", (@data[3])+(@data[2])+(@data[4]+0.5)); $uptime = `/usr/bin/uptime | sed 's/\ \ */ /g'`; @uptime = split(/,/, $uptime); @uptime = split(/up/, @uptime[0]); $server = `/bin/uname -n`; printf "@uptime[1]\n"; printf $server;

Relancer la configuration

cfgmaker --global 'WorkDir: /var/www/mrtg/' --global 'Language: French' 
--output /etc/mrtg.cfg [email protected] 
indexmaker /etc/mrtg.cfg --columns=2 --output /var/www/mrtg/index.html

Il faut biensur remplacer les chemins par ceux correspondant à votre configuration. Au final on obtient ceci

Related posts

Leave a Comment