MRTG on the NSLU2 - HowTo

Discussion in 'Cisco/Linksys Network Storage Devices' started by u3gyxap, May 25, 2005.

  1. u3gyxap

    u3gyxap Network Guru Member

    Couple weeks ago I ended with a NSLU2, that was a little promising devise. After some wondering around, I realized it would be the perfect solution for monitoring my WRTs, if it could run some sort of SNMP client. MRTG is the best I knew, so I made it my goal to have my slug running it to monitor my routers, on top of being a simple sabma share box.
    I don't have a spare linux machine, so I had to build it natively on the device. With the help of some coffee and the nslu2-linux community, I got it working. This is what you need to do:

    Make sure you have some 250MB available in /share/conf

    1. Install Unslung 3.18-beta and "unsling"
    2. Install crosstool-native

    # ipkg install crosstool-native

    (make sure that it installs ~117MB of files)

    3. Install the following packages: autoconf, automake, bash, bison, bzip2, coreutils, cvs, diffutils, ed, findutils, flex, gawk, grep, groff, libdb, libstdc++, m4, make, ncurses, openssh, patch, perl, sed, tar, wget-ssl, zlib, libpng, libjpeg, libgd. Not necessary in that order. After that you may want to reboot.

    4. Get MRTG from and decompress it in /opt/src/mrtg-2

    # cd /share/hdd/conf/tmp
    # wget
    # tar -xzv -f mrtg-2.11.1.tar.gz
    # cd /share/hdd/conf/tmp/mrtg-2.11.1

    5. Now, you decide where to install it. Let's say /opt/etc/mrtg-2

    # mkdir /opt/etc/mrtg-2

    5. For some odd reason, MRTG will look for libraries every place else but /opt/lib, so we need to point them.

    # LDFLAGS=-Wl,-rpath=/opt/lib
    # export LDFLAGS

    6. Now we begin configuring...

    # ./configure --prefix=/opt/etc/mrtg-2 \
    --with-gd-lib=/share/hdd/conf/opt/lib \
    --with-gd-inc=/share/hdd/conf/opt/include \
    --with-z-lib=/share/hdd/conf/opt/lib \
    --with-z-inc=/share/hdd/conf/opt/include \
    --with-png-lib=/share/hdd/conf/opt/lib \

    7. After some waiting it will configure. Then we "make" it.

    # make
    # make install

    After some more waiting mrtg makes itself comfortable in /opt/etc/mrtg-2

    Now you can use the built in script to configure it. It is in /opt/etc/mrtg-2/bin. More info on how to do that can be found here:


    I have another HowTo - setup a WRT54G running DD-WRT prefinal5 to report traffic, RSSI, SNR and so on trough SNMP to a machine running MRTG.

    It is a powerful combination :)

    More will be added on how to marry the Apache or the thttpd with the MRTG to make the MRTG output browsable directly on the NSLU2.
  2. u3gyxap

    u3gyxap Network Guru Member

    MRTG + thttpd HowTo.

    If you have done the above, you now have a working MRTG. Now you need to have a web server to serve the output. The NSLU2 has a thttpd built in. This is what you need to do in order to use it.
    You can also use Apache, but this is smaller, lighter and best of all - already there ;)

    1. Make a directory where you will have your thttpd. For an example /opt/etc/thttpd

    # mkdir /opt/etc/thttpd

    2. Copy (and rename) the thttpd and the conf file

    # cp /usr/sbin/thttpd /opt/etc/thttpd/mythttpd
    # cp /etc/thttpd.conf /opt/etc/thttpd/

    3. Edit your conf file, with changed port and path. This is what a .conf file might look like:


    If you don't have an editor, do this:

    # cat - >/opt/etc/thttpd/thttpd.conf

    Press Ctrls + C to save the file.
    Now you have a configured file that will point the httpd to visualize the content of /share/hdd/data/www to port 81.

    4. Launch the secondary thttpd.

    # /opt/etc/thttpd/mythttpd -C /opt/etc/thttpd/thttpd.conf

    You will need index.html in every directory and subdirectory served, otherwise the thttpd will just be showing the browse of the directories.

    Now, See if you like it. Go to ( you change with the IP of your SLUG)

    5. If you do, you should make a script to run it on boot.

    # cat - >/opt/etc/init.d/S81mythttpd
    /opt/etc/thttpd/mythttpd -C /opt/etc/thttpd/thttpd.conf

    Press Ctrl + C to save the file.

    # chmod a+x,u+x,g+x /opt/etc/init.d/S81mythttpd

    Now the NSLU2 will run it on boot.

    You may also want to check this out:
  3. NeuroticFish

    NeuroticFish Network Guru Member

    Sorry for digging up an old thread, but i need some help with this one.

    I have a working thttpd on my NSLU2 that i will use to load up the SNMP-data of my router (dd-wrt). When i execute my mrtg.cfg file, it queries the router correctly and writes the files correctly to my website-directory. However, i only have rw-permissions on the owner (root). I presume this is because i only can login in the NSLU2 under the root user (i think?) and the program writes it with only rw-permissions for the root (thus i'm not able to see it myself in my browser). I could solve this with chmod, but i was wondering if there wasn't a better method so i could solve this in once command (current command is /opt/mrtg-2/bin/mrtg /etc/mrtg.cfg).
  4. u3gyxap

    u3gyxap Network Guru Member

    mrtg.cfg is not executeable file. The command should look like this:
    /opt/etc/mrtg-2/bin/mrtg /share/hdd/data/www/mrtg/mrtg10.cfg
    if you have a user for the mrtg it should look like this:
    /opt/etc/mrtg-2/bin/mrtg /share/hdd/data/www/mrtg/mrtg10.cfg --user username
    The way I do it is to run the chmod command, which in my case is:
    chmod -R a+rx,u+rx,g+rx /share/hdd/data/www
    That I have executed 2-3 times during the initial start of mrtg and every time I add or change OID.
    The other way around which is also the easyiest will be to have thttpd and the mrtg to run as root, then you will have no probs with the permitions.
  5. NeuroticFish

    NeuroticFish Network Guru Member

    Thx man, i've solved it by adding the line " 0,5,10,15,20,25,30,35,40,45,50,55 * * * * root /opt/mrtg-2/bin/mrtg /etc/mrtg.cfg ; chmod –R a+rx,u+rx,g+rx /website &>/dev/null " to my crontab-file, seems to work flawless now. Have to fiddle around in the configfile for MRTG though, so many options!

    I do notice it keeps writing a line to my /var/log/messages file. Is the messages-file restricted in size? Or will it just keep on growing? Is it also reset after a reboot of my Slug?

    I was wondering also where MRTG keeps the mrtg.log file with all the data in it. I've checked /var/log, but it's not there. I want to delete it, because the system time of my Slug was set wrong and now that I've adjusted it, it won't update anymore untill it has reached the previous system-data.
  6. u3gyxap

    u3gyxap Network Guru Member

    Instead of executing it every 5 minutes, you can just set it up as a daemon. Write this as a first line in mrtg.cfg:
    RunAsDaemon: Yes
    I don't think you have logging enabled, unless you have included this so the line looks like this:
    " 0,5,10,15,20,25,30,35,40,45,50,55 * * * * root /opt/mrtg-2/bin/mrtg /etc/mrtg.cfg --logging /var/log/mrtg.log ; chmod –R a+rx,u+rx,g+rx /website &>/dev/null"

    I have noticed that you use /website
    Not sure which version of unslung you are using, but in my case, 3.8, I do not use "/" directory for nothing, becouse that is my flash. Everything goes to /share/hdd/data or /opt
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice