Multi Router Traffic Grapher (MRTG) est un logiciel développé sous licence GNU/GPL à l'initiative de Tobi Oetiker. Ce logiciel permet de créer des graphiques sur le trafic réseau. Il utilise le protocole SNMP pour interroger des équipements réseaux tels que des routeurs, commutateurs, ou bien encore serveurs, disposant d'une MIB. (source : wikipedia)
apt-get install mrtg snmpd
cp /etc/mrtg.cfg /etc/mrtg.cfg_old cfgmaker public@localhost > /etc/mrtg.cfg
Un crontab tourne toute les 5 minutes pour l'utilisateur root
cat /etc/cron.d/mrtg
| 0-55/5 * * * * | root if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ];then env LANG=C /usr/bin/mrtg /etc/mrtg.cfg » /var/log/mrtg/mrtg.log 2>&1; fi |
|---|
vi /etc/snmp/snmpd.conf
sec.name source community #com2sec paranoid default public com2sec readonly default public #com2sec readwrite default private
/etc/init.d/snmpd restart
indexmaker --columns=1 --output /var/www/mrtg/index.html /etc/mrtg.cfg
Gestion du CPU, RAM…
### Global Config Options # for Debian WorkDir: /var/www/mrtg Options[_]: bits,growright WriteExpires: Yes Title[^]: Traffic Analysis for ### Global Defaults # to get bits instead of bytes and graphs growing to the right # Options[_]: growright, bits EnableIPv6: no ### Global Config Graf # Gestion de la bande passante Target[localhost_2]: 2:public@localhost: Options[localhost_2]: growright SetEnv[localhost_2]: MRTG_INT_IP="MON_IP" MRTG_INT_DESCR="eth0" MaxBytes[localhost_2]: 1250000 Title[localhost_2]: Bande passante PageTop[localhost_2]: <h1>Bande passante</h1> # Gestion de la bande passante v2 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]: <H1>Entree/Sortie/Pourcentage du traffic</H1> # Gestion de l'utilsation du CPU LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@127.0.0.1+ ssCpuRawSystem.0&ssCpuRawSystem.0:public@127.0.0.1+ ssCpuRawNice.0&ssCpuRawNice.0:public@127.0.0.1 RouterUptime[localhost.cpu]: public@127.0.0.1 MaxBytes[localhost.cpu]: 100 Title[localhost.cpu]: CPU Load PageTop[localhost.cpu]: <h1>Active CPU Load %</h1> Unscaled[localhost.cpu]: ymwd ShortLegend[localhost.cpu]: % YLegend[localhost.cpu]: CPU Utilization Legend1[localhost.cpu]: Active CPU in % (Load) Legend2[localhost.cpu]: Legend3[localhost.cpu]: Legend4[localhost.cpu]: LegendI[localhost.cpu]: Active LegendO[localhost.cpu]: Options[localhost.cpu]: nopercent,growright # Gestion de l'utilisation de la RAM Target[mem]: `/etc/mrtg/mem.sh` Options[mem]: nopercent,growright,gauge,noinfo,nobanner #Unscaled[mem]:dwmy MaxBytes[mem]: 3221225472 Kilo[mem]:1024 YLegend[mem]: RAM ShortLegend[mem]: o Legend1[mem]: Memoire libre Legend2[mem]: Memoire utilisee LegendI[mem]: Mem. utilisée LegendO[mem]: Mem. libre Title[mem]: Memoire PageTop[mem]: <h1>Memoire</h1> WithPeak[mem]:wmy #Legend3[mem]: Memoire libre max #Legend4[mem]: Memoire utilise max # Gestion de la charge du serveur # Gestion du nombre de joueur Target[minecraft]: `/home/root/scripts/minequery.php` MaxBytes[minecraft]: 50 Title[minecraft]: Population du serveur Minecraft PageTop[minecraft]: <h1>Nombre de joueurs</h1> #Unscaled[minecraft]: ymwd ShortLegend[minecraft]: joueurs YLegend[minecraft]: Nombre de joueurs Legend1[minecraft]: Joueurs LegendI[minecraft]: Joueurs LegendO[minecraft]: Joueurs Options[minecraft]: nopercent,growright,gauge,integer
indexmaker --columns=1 --output /var/www/mrtg/index.html /etc/mrtg.cfg
#!/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
#!/usr/bin/php <?php $host = "nom_dns_du_srv.com"; /* Minecraft - plugin Minequery */ require_once("minequery.class.php"); $mc_status = new Minequery($host); $count = $mc_status->player_count(); echo $count."\n"; echo $count."\n"; ?>
chmod +x script.pl