Ci-dessous, les différences entre deux révisions de la page.
install:mrtg [2008/09/07 14:58] linkuff |
install:mrtg [2011/02/02 22:42] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | Ce tutoriel a pour but d' | ||
- | |||
- | |||
- | |||
- | ===== Installation de base SNMP et MRTG : ===== | ||
- | Installer snmpd : | ||
- | < | ||
- | apt-get install snmpd | ||
- | </ | ||
- | |||
- | Editer le fichier de configuration du serveur snmp afin de le rendre utilisable par MRTG : | ||
- | < | ||
- | vi / | ||
- | </ | ||
- | décommenter cette ligne : | ||
- | < | ||
- | com2sec readonly | ||
- | </ | ||
- | |||
- | Redémarrer snmpd : | ||
- | < | ||
- | / | ||
- | </ | ||
- | |||
- | Installer MRTG : | ||
- | < | ||
- | apt-get install mrtg | ||
- | </ | ||
- | |||
- | Créer le dossier /etc/mrtg qui contiendra les scripts spécifiques : | ||
- | < | ||
- | mkdir /etc/mrtg | ||
- | </ | ||
- | |||
- | Créer l' | ||
- | < | ||
- | indexmaker --output / | ||
- | </ | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ===== Création des scripts : ===== | ||
- | |||
- | Ajouter le script ping / | ||
- | < | ||
- | #!/bin/sh | ||
- | P=`ping | ||
- | MIN=`echo $P|cut -d"/" | ||
- | MAX=`echo $P|cut -d"/" | ||
- | echo $MAX | ||
- | echo $MIN | ||
- | </ | ||
- | |||
- | Ajouter le script mem / | ||
- | < | ||
- | #!/bin/sh | ||
- | USED=`free -b|grep cache:|cut -d ":" | ||
- | FREE=`free -b|grep cache:|cut -d ":" | ||
- | echo $FREE | ||
- | echo $USED | ||
- | </ | ||
- | |||
- | Pour utiliser le script CPU, il faut installer le package sysstat (commande sar) : | ||
- | < | ||
- | apt-get install sysstat | ||
- | </ | ||
- | |||
- | Activer le processus sysstat en remplaçant FALSE par TRUE dans le fichier / | ||
- | < | ||
- | # ENABLED=" | ||
- | ENABLED=" | ||
- | </ | ||
- | |||
- | Ajouter le script cpu / | ||
- | < | ||
- | # | ||
- | @line = `/ | ||
- | @data = split(/ /, @line[0]); | ||
- | if (@data[2] eq "" | ||
- | printf " | ||
- | }else { | ||
- | printf (" | ||
- | } | ||
- | printf (" | ||
- | $uptime = `/ | ||
- | @uptime = split(/,/, $uptime); | ||
- | @uptime = split(/up/, @uptime[0]); | ||
- | $server = `/bin/uname -n`; | ||
- | printf " | ||
- | printf $server; | ||
- | </ | ||
- | |||
- | Ajouter le script cpu / | ||
- | < | ||
- | # | ||
- | #Affichage de la consommation cpu pour MRTG | ||
- | my $cpu =`cat /proc/stat | grep " | ||
- | $cpu=~ /cpu (.*) (.*) (.*) (.*)/; | ||
- | my $conso = $1 + $2 + $3; | ||
- | $conso = int($conso); | ||
- | print " | ||
- | print " | ||
- | </ | ||
- | |||
- | Pour installer le monitoring Apache 2, il faut décommenter la partie server-status dans la configuration d' | ||
- | < | ||
- | vi / | ||
- | </ | ||
- | |||
- | Verifier la présence de ses lignes, les ajouter si besoin : | ||
- | < | ||
- | < | ||
- | SetHandler server-status | ||
- | Order deny,allow | ||
- | Deny from all | ||
- | Allow from 127.0.0.1 | ||
- | </ | ||
- | ExtendedStatus On | ||
- | </ | ||
- | |||
- | sauvegarder le ficher et redémarrer apache2 : | ||
- | < | ||
- | / | ||
- | </ | ||
- | |||
- | Ajouter le script apache2 / | ||
- | < | ||
- | # | ||
- | # can return hits or bytes (counters) | ||
- | @res = `lynx -dump http:// | ||
- | foreach $res (@res) { | ||
- | if ($res =~ /Server uptime: (.*)$/) { $up = $1; last } else { next } | ||
- | if ($res =~ /Server at/) { $server = $res; last } else { next } | ||
- | } | ||
- | |||
- | @res = `lynx -dump http:// | ||
- | |||
- | foreach $res (@res) { | ||
- | if ($res =~ /Total Accesses: (\d+)/) { $d1 = $1; next } | ||
- | if ($res =~ /Total kBytes: (\d+)/) { $d2 = $1 * 1024; next } | ||
- | } | ||
- | $d1 = int($d1); | ||
- | $d2 = int($d2); | ||
- | if ($ARGV[0] eq " | ||
- | print " | ||
- | print " | ||
- | } elsif ($ARGV[0] eq " | ||
- | print " | ||
- | print " | ||
- | } | ||
- | print " | ||
- | print " | ||
- | </ | ||
- | |||
- | Pour permettre l' | ||
- | < | ||
- | chmod 700 /etc/mrtg/* | ||
- | </ | ||
- | |||
- | |||
- | ===== Génération des stats : ===== | ||
- | Voila, maintenant que les scripts sont prêt, il faut faire les appels dans le fichier de conf :) | ||
- | |||
- | Ajouter la configuration du script ping à / | ||
- | < | ||
- | # | ||
- | Target[ping_yahoo]: | ||
- | Options[ping_yahoo]: | ||
- | MaxBytes[ping_yahoo]: | ||
- | AbsMax[ping_yahoo]: | ||
- | YLegend[ping_yahoo]: | ||
- | ShortLegend[ping_yahoo]: | ||
- | Legend1[ping_yahoo]: | ||
- | Legend2[ping_yahoo]: | ||
- | LegendI[ping_yahoo]: | ||
- | LegendO[ping_yahoo]: | ||
- | Title[ping_yahoo]: | ||
- | PageTop[ping_yahoo]: | ||
- | WithPeak[ping_yahoo]: | ||
- | Legend4[ping_yahoo]: | ||
- | Legend3[ping_yahoo]: | ||
- | # | ||
- | |||
- | # | ||
- | Target[mem]: | ||
- | Options[mem]: | ||
- | Unscaled[mem]: | ||
- | MaxBytes[mem]: | ||
- | Kilo[mem]: | ||
- | YLegend[mem]: | ||
- | ShortLegend[mem]: | ||
- | Legend1[mem]: | ||
- | Legend2[mem]: | ||
- | LegendI[mem]: | ||
- | LegendO[mem]: | ||
- | Title[mem]: Mémoire | ||
- | PageTop[mem]: | ||
- | WithPeak[mem]: | ||
- | Legend3[mem]: | ||
- | Legend4[mem]: | ||
- | # | ||
- | |||
- | # | ||
- | Target[cpu]: | ||
- | Options[cpu]: | ||
- | # | ||
- | MaxBytes[cpu]: | ||
- | YLegend[cpu]: | ||
- | ShortLegend[cpu]: | ||
- | Legend1[cpu]: | ||
- | Legend2[cpu]: | ||
- | LegendI[cpu]: | ||
- | LegendO[cpu]: | ||
- | Title[cpu]: CPU | ||
- | PageTop[cpu]: | ||
- | WithPeak[cpu]: | ||
- | Legend3[cpu]: | ||
- | Legend4[cpu]: | ||
- | # | ||
- | |||
- | # | ||
- | Target[cpu2]: | ||
- | Options[cpu2]: | ||
- | Title[cpu2]: | ||
- | MaxBytes[cpu2]: | ||
- | YLegend[cpu2]: | ||
- | ShortLegend[cpu2]: | ||
- | LegendO[cpu2]: | ||
- | Legend2[cpu2]: | ||
- | PageTop[cpu2]: | ||
- | WithPeak[cpu2]: | ||
- | Legend3[cpu2]: | ||
- | Legend4[cpu2]: | ||
- | # | ||
- | |||
- | # | ||
- | Target[apache2_hits]: | ||
- | Options[apache2_hits]: | ||
- | PageTop[apache2_hits]: | ||
- | MaxBytes[apache2_hits]: | ||
- | YLegend[apache2_hits]: | ||
- | ShortLegend[apache2_hits]: | ||
- | LegendO[apache2_hits]: | ||
- | Legend2[apache2_hits]: | ||
- | Legend4[apache2_hits]: | ||
- | Title[apache2_hits]: | ||
- | WithPeak[apache2_hits]: | ||
- | # | ||
- | |||
- | # | ||
- | Target[apache2_traffic]: | ||
- | Options[apache2_traffic]: | ||
- | PageTop[apache2_traffic]: | ||
- | MaxBytes[apache2_traffic]: | ||
- | AbsMax[apache2_traffic]: | ||
- | YLegend[apache2_traffic]: | ||
- | ShortLegend[apache2_traffic]: | ||
- | LegendO[apache2_traffic]: | ||
- | Legend2[apache2_traffic]: | ||
- | Title[apache2_traffic]: | ||
- | WithPeak[apache2_traffic]: | ||
- | Legend4[apache2_traffic]: | ||
- | # | ||
- | </ | ||
- | |||
- | Et pour finir, générez l' | ||
- | < | ||
- | indexmaker --columns=2 --output / | ||
- | </ |