RRDTool for DD-WRT (Working howto!)

Discussion in 'DD-WRT Firmware' started by GoldServe, Jan 26, 2006.

  1. GoldServe

    GoldServe Network Guru Member

    I got RRDTool to run by modifying a whole slew of things to make it work on /jffs rather than a writable root like the openwrt.

    I have one challenge left. I don't know how to run the rrd.cgi script that is generated. I've tried running it with mini_httpd from bwlog and httpd from dd-wrt itself. It seems as though the cgi application is not working.

    Maybe a httpd with CGI not in the standard /usr/bin locations have to be compiled. I don't know. Please contact me if you have the knowledge of cgi apps on the dd-wrt platform.

    Anyways, here is a teaser and a mockup of what the cgi is supposed to look like:



    <HEAD><TITLE>RRDCGI Router Statistics</TITLE></HEAD>
    <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
    function update_radio_check(robj,value) { for (var i=0; i<robj.length; i++) if (robj[i].value==value) robj[i].checked=1; }
    var nW,oW;
    function zoomToggle(iWideSmall,iWideLarge,whichImage){
    <BODY onload="update_radio_check(document.RangeForm.START,'<RRD::CV START>')">
    <H1>RRDCGI Router Statistics <font size-=2>[i](<RRD::TIME::NOW %c>)[/i]</font></H1>
    <FORM NAME=RangeForm>
          <INPUT NAME=START TYPE=RADIO VALUE=end-24h checked>24 hours ago
          <INPUT NAME=START TYPE=RADIO VALUE=end-7d>7 days ago
          <INPUT NAME=START TYPE=RADIO VALUE=end-4w>4 weeks ago
    </TR><TR> <TD valign=top>System Load (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/SYS_USG_STATS.def>
     <TD valign=top>CPU Usage (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/SYS_CPU_STATS.def>
    </TR><TR> <TD valign=top>Memory Usage (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/SYS_MEM_STATS.def>
     <TD valign=top>Flash Disk Usage (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/SYS_DSK_STATS.def>
    </TR><TR> <TD valign=top>Misc (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/SYS_MISC_STATS.def>
     <TD valign=top>Interrupts (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/SYS_IRQ_STATS.def>
    </TR><TR> <TD valign=top>Lan Interface Traffic Statistics (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/IF_LAN_TRAFFIC.def>
     <TD valign=top>Lan Interface Packets Statistics (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/IF_LAN_PACKETS.def>
    </TR><TR> <TD valign=top>Wan Interface Traffic Statistics (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/IF_WAN_TRAFFIC.def>
     <TD valign=top>Wan Interface Packets Statistics (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/IF_WAN_PACKETS.def>
    </TR><TR> <TD valign=top>Wifi Interface Traffic Statistics (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/IF_WIFI_TRAFFIC.def>
     <TD valign=top>Wifi Interface Packets Statistics (FPOS)
      <RRD::INCLUDE /jffs/var/lib/rrdcollect/img/IF_WIFI_PACKETS.def>
  2. GoldServe

    GoldServe Network Guru Member

    Download at: http://www.ece.uwaterloo.ca/~kzlo/rrd_jffs.zip

    1) Make sure you have enough room in your JFFS, around 2mb I estimate
    2) download the above archive and make/extract the files to the exact same directory struct as the zip file
    3) start the rrdcollect daemon by typing /jffs/etc/init.d/S98rrdcollect start
    4) make sure there were no errors in the previous statement. Two rrd files should be created in /jffs/var/lib/rrdcollect/rrd
    5) generate the cgi script by byping /jffs/usr/bin/rrd.sh cgi
    6) make sure there were no errors in the previous statement. a rrd.cgi script should be created in /jffs/var/lib/rrdcollect/

    Configure the http part now

    1) make a www director in tmp:
    cd /tmp
    mkdir www
    2) make cgi-bin director in www:
    cd /tmp/www
    mkdir cgi-bin
    3) link the necessary files:
    ln -s /jffs/var/lib/rrdcollect/rrd.cgi /tmp/www/cgi-bin/rrd.sh
    ln -s /jffs/var/lib/rrdcollect/img /tmp/www/img

    Now go to:
    http://<router ip>/user/cgi-bin/rrd.sh

    What I hope to achieve from this is a spark of interest to develop better and nicer looking graphs, somehow integrated to the dd-wrt looking interface.

    I have the following ideas:

    1. average ping time to a site
    2. average, noise, signal graph
    3. number of clients connected
    4. ...
  3. sis3970

    sis3970 Network Guru Member

    Wow, this is very nice!!
    You don't happen to have a clue why the "submit query" results in a "page cannot be displayed" error?

  4. _splat_

    _splat_ Network Guru Member

    Is it possible to "shrink" rrdcollect down to 1mb ?
    I have a wrt54G and with DD-WRT-mini firmware just 1mb left on jffs.

    I wonder why this script takes so much space.
    Or would it be possible that the script saves the graphs or something on a SMBshare?

  5. GoldServe

    GoldServe Network Guru Member

    Here is my updated guide with the DD-WRT looking interface and scripts to gather host by host statistics.

    Download at: http://www.ece.uwaterloo.ca/~kzlo/rrd_jffs_new.zip

    I am using an MMC card mounted as JFFS so look below for instructions on how to do that.

    1) Make sure you have enough room on your MMC card, around 2mb I estimate.

    2) Enable JFFS in DD-WRT but not MMC.

    3) Reboot the router and issue the following commands:

    umount /jffs
    cd /tmp
    insmod /lib/modules/2.4.32/kernel/fs/mmc/mmc.o
    insmod /lib/modules/2.4.32/kernel/fs/fat/fat.o
    insmod /lib/modules/2.4.32/kernel/fs/vfat/vfat.o
    mount -t vfat /dev/mmc/disc0/part1 /jffs
    4) Make sure you have the mmc card mounted as /jffs

    ~ # mount
    /dev/root on / type squashfs (ro)
    none on /dev type devfs (rw)
    proc on /proc type proc (rw)
    ramfs on /tmp type ramfs (rw)
    /dev/mmc/disc0/part1 on /jffs type vfat (rw)
    2) Download the above archive and make/extract the files to the exact same directory structure as the zip file. Use windows, unzip the file to a directory. Use WinSCP to log onto your router (with SSHD enabled) and copy the folder jffs to / overwriting the jffs folder and creating all the necessary folders and files on the jffs card.

    3) Edit rrdcollect.conf in /jffs/etc/ to include the IPs you want to monitor:

    exec:///usr/sbin/iptables -n -v -x -t mangle -L POSTROUTING | grep | awk '{print $2}'
    "%d"                                            AC.rrd:TIB100
    exec:///usr/sbin/iptables -n -v -x -t mangle -L PREROUTING | grep | awk '{print $2}'
    "%d"                                            AC.rrd:TOB100
    exec:///usr/sbin/iptables -n -v -x -t mangle -L POSTROUTING | grep | awk '{print $2}'
    "%d"                                            AC.rrd:TIB102
    exec:///usr/sbin/iptables -n -v -x -t mangle -L PREROUTING | grep | awk '{print $2}'
    "%d"                                            AC.rrd:TOB102
    (Here I am monitoring .100 and .102)

    4) Edit rrd.conf in /jffs/etc/ to include the IPs you want to monitor:

    # Traffic Accounting Stats
    ACI="Incoming for "; ACO="Outgoing for "
    IP100="tge     "; COL100=$ORG0; COL_100=$ORG1
    IP102="gs      "; COL102=$BLU0; COL_102=$BLU1
    #IP20="aplink  "; COL20=$GRN0; COL_20=$GRN1
    #IP50="sunny   "; COL50=$BLU0; COL_50=$BLU1
    for i in 102 100
            # Packet-Statistics
    (Change all the references of 100 and 102)

    5) Add the rule to monitor the traffic of each host in the iptables by issuing:

    /usr/sbin/iptables -t mangle -I POSTROUTING -j MARK --set-mark 15 -d
    /usr/sbin/iptables -t mangle -I PREROUTING -j MARK --set-mark 15 -s
    /usr/sbin/iptables -t mangle -I POSTROUTING -j MARK --set-mark 15 -d
    /usr/sbin/iptables -t mangle -I PREROUTING -j MARK --set-mark 15 -s
    6) Start the rrdcollect daemon by typing:

    ~# /jffs/etc/init.d/S98rrdcollect start
    7) Make sure there were no errors in the previous statement. Three rrd files should be created in /jffs/var/lib/rrdcollect/rrd. If not, issue the following command and make sure there are no errors:

    ~# /jffs/usr/bin/rrd.sh init
    5) Generate the cgi script by by typing:

    ~# /jffs/usr/bin/rrd.sh cgi
    (rrd.cgi should be generated in /jffs/var/lib/rrdcollect)

    6) Set up DD-WRT so that the internal httpd can view the page by typing the following commands:

    mkdir /tmp/www
    mkdir /tmp/www/cgi-bin
    ln -s /jffs/var/lib/rrdcollect/img /tmp/www/img
    ln -s /jffs/var/lib/rrdcollect/rrd.cgi /tmp/www/cgi-bin/rrd.sh
    cp /jffs/var/lib/rrdcollect/cyan.css /tmp/www/cgi-bin/cyan.css
    7) You can view the page now at http://<router IP>/user/cgi-bin/rrd.sh

  6. GoldServe

    GoldServe Network Guru Member

    Some examples


    RRD Graph for 2 hosts:


    Image for two hosts doing bittorrent. Combined, I can get around 350kb/sec as indicated by the graph. Cools!
  7. GoldServe

    GoldServe Network Guru Member


    The updated package includes a theme for dd-wrt and does not have the submit buttons anymore. The HTTPD server built in doesn't support it and i don't know how to get around it. I've hard coded the page to display 24 hour graphs only and you can display up to 4 week's worth of data if you hack around the rrd.sh generating the cgi page or the generated cgi file itself. Enjoy!


    Of course you can sktrink this down QUITE a bit. Because I have a mmc card mod, space is not an issue to me. I change it to collect data every 120 seconds, 1 pixel resolution. I can change it to collect every 5 minutes, 2 for resolution, keep up to 1 week's worth of data. You can even hack the scripts or config files to generate the images into your /tmp directory. Enjoy!
  8. akumulator

    akumulator Network Guru Member

    Statistics for IP addresses


    This looks great! Good job!!!

    It is possible to count the trafic for particular IPs? I need to know how much kb(MB) has been downloaded/uploaded by each user for a specific period...

    For ex:
    1/1/2006 - 1/31/2006: Upload 250MB, Dowload 2.3GB Upload 23MB, Dowload 540MB

    Is there some more documentation about your project?

    Thanks a lot!

  9. GoldServe

    GoldServe Network Guru Member

    You can go to http://forum.bsr-clan.de/viewtopic.php?t=4802&highlight=rrdtool for more detailed information on how to set this up.

    RRDTool was not designed to be an accounting stat program. It does an average over the time interval so your data is not accurate.

    However, there are tools out there that will do traffic accounting. Most of them extract ddata from the ifconfig but if you use my connection marking, you can get total bytes for a particular IP.

    You'll need to do a little rewriting of the scripts to achieve what you want. Cheers!
  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