Tool-BarfreeBSD ArticlesSearch Our SiteHOMEfreeBSD LinksContribute to FreeBSD HelpFreeBSD FilesFreeBSD Script Corner

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
  # pkg_add ucd-snmp-4.1.2.tgz
Now we can start snmpd
  # /usr/local/sbin/snmpd
This should start snmpd up nice and smoothly.
To setup a startup script for it.
  # ee /usr/local/etc/rc.d/
  echo -n ' snmpd'
 # chmod +x /usr/local/etc/rc.d/
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
 # gunzip -c zlib.tar.gz | tar xf -
 # mv zlib-?.?.?/ zlib
 # cd zlib
 # ./configure
 # make
 # cd ..
If you don't have libpng installed
 # wget
 # 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
 # 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
  # 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:
  # ./configure
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   \
       --with-z=/usr/local/src/zlib   \
  # make
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. community@ 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.
Running MRTG
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/ http://localhost/~mrtg/  http://localhost/~mrtg/ http://localhost/~mrtg/
And so on, depending how many interfaces you have.
HOWTO Done by whisky

© 1997 - 20013 Defcon1, , Copyrights for all materials on this web site are held by the individual authors, artists, photographers or creators. Materials may not be reproduced or otherwise distributed without permission of and the content's original author.

Tool-Bar-2Defcon1  Webmail