MRTG - Multi Router Traffic Grapher HOWTO
MRTG as it is otherwise known as, is a daemon to graph on a webpage the stats for nics and routers. For this howto we will discuss howto make a graph for a nic interface ep0. You will also need to install SNMPD which I will be covering also, and it helps to have apache going. Ok here we go =) good luck.
First off you are going to need SNMPD.
If you do not have wget then
# cd /usr/ports/ftp/wget/
# make install clean
Now you can get the snmpd package using wget
# cd /root/
# wget ftp://ftp.freebsd.org/.0/FreeBSD/ports/i386/packagesstable/net/ucd-snmp-4.1.2.tgz
# pkg_add ucd-snmp-4.1.2.tgz
Now we can start snmpd
This should start snmpd up nice and smoothly.
To setup a startup script for it.
# ee /usr/local/etc/rc.d/snmpd.sh
echo -n ' snmpd'
# chmod +x /usr/local/etc/rc.d/snmpd.sh
Next we are going to install the dependecies for mrtg.
# mkdir -p /usr/local/src
# cd /usr/local/src
If you do not have zlib installed:
# wget http://ftp.info-zip.org/pub/infozip/zlib/zlib.tar.gz
# gunzip -c zlib.tar.gz | tar xf -
# mv zlib-?.?.?/ zlib
# cd zlib
# cd ..
If you don't have libpng installed
# wget http://www.libpng.org/pub/png/src/libpng-1.0.8.tar.gz
# gunzip -c libpng-1.0.8.tar.gz |tar xf -
# mv libpng-1.0.8 libpng
# cd libpng
# make -f scripts/makefile.std CC=gcc ZLIBLIB=../zlib ZLIBINC=../zlib
# rm *.so.* *.so
# cd ..
And now you can compile gd
# wget http://www.boutell.com/gd/http/gd-1.8.3.tar.gz
# gunzip -c gd-1.8.3.tar.gz |tar xf -
# mv gd-1.8.3 gd
# cd gd
The \ characters at the end of the line mean that all the following material should actually be written on a single line.
# make INCLUDEDIRS="-I. -I../zlib -I../libpng" \
LIBDIRS="-L../zlib -L. -L../libpng" \
LIBS="-lgd -lpng -lz -lm"
# cd ..
Ok now everything is ready for the mrtg compilation.
# cd /usr/local
# wget http://whisky.warnerve.net/files/mrtg-2.9.6.tar.gz
# gunzip -c mrtg-2.9.6.tar.gz | tar xvf -
# cd mrtg-2.9.6
If you all the libraries have been preinstalled on your system you can configure mrtg by doing a simple:
Otherwise you may have to give some hints on where to find the various libraries required to compile mrtg:
# ./configure --with-gd=/usr/local/src/gd \
CREATING THE CONFIG
Ok mrtg runs off a mrtg.cfg that you have to create. Don't worry there is a nice little program called cfgmaker that is a great asset to you.
# cd /usr/local/mrtg-2.9.6/bin/
# ./cfgmaker --global 'WorkDir: /home/mrtg/public_html' \
--global 'Options[_]: bits,growright' \
--output /home/mrtg/mrtg.cfg \
The \ characters at the end of the line mean that all the following material should actually be written on a single line. This setup is presuming that there is a directory /home/mrtg/ and he has a public_html directory with apache for web pages. email@example.com is used to access snmpd with gives stats on all nics ( Network Interface Card ) on the system.
If you want the bottom pictures to work then do as follows.
# cp /usr/local/mrtg-2.9.6/doc/*.png /home/mrtg/public_html
Or whereever the webdir is for it.
Mrtg needs to be run to update the .html files all the time to display new stats. I recommend running a cron.
But this is how you run it.
# /usr/local/mrtg-2.9.6/bin/mrtg /home/mrtg/mrtg.cfg
Assuming /home/mrtg/mrtg.cfg is where you put the mrtg.cfg
Now to setup a crontab for it do as follows.
I like to keep my crons organised for root so I have a file called /root/crons where I place all my crontabs for root.
# ee /root/crons
*/5 * * * * /usr/local/mrtg-2.9.6/bin/mrtg /home/mrtg/mrtg.cfg >/dev/null 2>&1
# crontab /root/crons
This will run it every 5 mins and update the graphs.
Viewing the Graphs
If you followed this setup then you should find your graphs at http://localhost/~mrtg/127.0.0.1_1.html http://localhost/~mrtg/127.0.0.1_2.html http://localhost/~mrtg/127.0.0.1_3.html http://localhost/~mrtg/127.0.0.1_3.html
And so on, depending how many interfaces you have.
HOWTO Done by whisky