Defcon-1-Logo

           [Home]    [FBSD Articles]    [Scripts Corner]    [Contribute]    [Search]    [FBSD Links]    [Files]

About Us

FreeBSD Articles
  *Hardware
  *Networking
  *Security
  *Software
  *X Windows


Files / Scripts
Newbies Corner
Tech. Talk
Tips and Tricks


FreeBSD Links

Articles in other
Languages :
  *French Articles
  *Spanish Articles

Want to Help ?
 
   Click Here

Email Users5

Search:
 

 


FreeBSD Search:


 

 

Powered-By-Apache-Logo
Defcon1 Logo

Multi Router Traffic Grapher HOWTO

MRTG

EXAMPLES

http://stats.warnerve.net/

OVERVIEW

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.

INSTALLATION

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

  # /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/snmpd.sh
 
  #!/bin/sh
  /usr/local/sbin/snmpd
  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
 # ./configure
 # make
 # 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:

  # ./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   \
       --with-png=/usr/local/src/libpng

  # make

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  \
      community@127.0.0.1

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@127.0.0.1 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

CRONTAB

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 whisky@warnerve.net

You can find us on EFNet #freebsdhelp

Email Us

ghostrdr@defcon1.org

This site cannot be duplicated without permission

© 1998 - 2010 Defcon1, www.defcon1.org. 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 www.defcon1.org and the content's original author.