Bandbreitennutzung mittels MRTG überwachen

Überwachung der Bandbreite vom Lokalen Host

MRTG installieren

root@suffix:~# aptitude install apache2 mrtg
root@suffix:~# mkdir /etc/mrtg && sudo mv /etc/mrtg.cfg /etc/mrtg
root@suffix:~# mkdir /var/www/mrtg

 

Bevor nun MRTG zum 1. Mal gestartet wird muss der SNMP-Daemon noch installiert und konfiguriert werden

root@suffix:~# aptitude install snmp snmpd

 

In der Konfigurationdatei /etc/default/snmp sollte Zeile 12 durch folgende Zeile ausgetauscht werden.

SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'
root@suffix:~# cat /etc/default/snmp
1 # This file controls the activity of snmpd and snmptrapd
2
3 # Don't load any MIBs by default.
4 # You might comment this lines once you have the MIBs downloaded.
5 export MIBS=
6
7 # snmpd control (yes means start daemon).
8 SNMPDRUN=yes
9
10 # snmpd options (use syslog, close stdin/out/err).
11 #SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid'
12 SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'

 

Eine simple Konfiguration von /etc/snmp/snmpd.conf (Für diesen Zweck ausreichend!)

root@suffix:~# cat /etc/snmp/snmpd.conf
rocommunity    public   
sysLocation    Keller
sysContact     k3ops

 

SNMP-Daemon neustarten

root@suffix:~# service snmpd restart (oder /etc/init.d/snmpd restart)

 

Abschlusskonfiguration MRTG

root@suffix:~# cfgmaker --output=/etc/mrtg/localhost.cfg public@127.0.0.1
--base: Get Device Info on public@127.0.0.1: --base: Vendor Id: Unknown Vendor - 1.3.6.1.4.1.8072.3.2.10 --base: Populating confcache --base: Get Interface Info --base: Walking ifIndex --snpd: public@127.0.0.1: -> 1 -> ifIndex = 1 --snpd: public@127.0.0.1: -> 2 -> ifIndex = 2 --base: Walking ifType --snpd: public@127.0.0.1: -> 1 -> ifType = 24 --snpd: public@127.0.0.1: -> 2 -> ifType = 6 --base: Walking ifAdminStatus --snpd: public@127.0.0.1: -> 1 -> ifAdminStatus = 1 --snpd: public@127.0.0.1: -> 2 -> ifAdminStatus = 1 --base: Walking ifOperStatus --snpd: public@127.0.0.1: -> 1 -> ifOperStatus = 1 --snpd: public@127.0.0.1: -> 2 -> ifOperStatus = 1 --base: Walking ifMtu --snpd: public@127.0.0.1: -> 1 -> ifMtu = 16436 --snpd: public@127.0.0.1: -> 2 -> ifMtu = 1500 --base: Walking ifSpeed --snpd: public@127.0.0.1: -> 1 -> ifSpeed = 10000000 --snpd: public@127.0.0.1: -> 2 -> ifSpeed = 100000000 --base: Writing /etc/mrtg/localhost.cfg

 

Die #Global Settings werden in der /etc/mrtg/localhost.cfg folgend angepasst

root@suffix:~# cat /etc/mrtg/localhost.cfg
#Global Settings
RunAsDaemon: yes
EnableIPv6: no
WorkDir: /var/www/mrtg
Options[_]: bits,growright
WriteExpires: Yes
### Interface 1 >> Descr: 'lo' | Name: 'lo' | Ip: '127.0.0.1' | Eth: 'No Ethernet Id' ###
### The following interface is commented out because:
...
Target[127.0.0.1_eth0]: #eth0:public@127.0.0.1:
SetEnv[127.0.0.1_eth0]: MRTG_INT_IP="192.168.XXX.XXX" MRTG_INT_DESCR="eth0"
MaxBytes[127.0.0.1_eth0]: 12500000
Title[127.0.0.1_eth0]: Traffic Analysis for eth0 -- suffix
...

 

MRTG starten und Bandbreiten Status Webseite erzeugen

root@suffix:~# env LANG=C /usr/bin/mrtg /etc/mrtg/localhost.cfg

Es kann sein dass beim Starten von MRTG von Ubuntu gemecket wird dass /var/www/mrtg nicht existiert… einfach von Hand erstellen und mrtg erneut starten

root@suffix:~# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/localhost.cfg

 

MRTG process prüfen

root@suffix:~# ps ax | grep mrtg
11814 ? Ss 0:00 /usr/bin/perl -w /usr/bin/mrtg /etc/mrtg/localhost.cfg 25979 pts/0 R+ 0:00 grep --color=auto mrtg 

MRTG Process stoppen

root@suffix:~# kill 11814

 

Unter http://IP/mrtg kann die so eben erzeugte index.htm im Browser aufgerufen werden.