1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bandwidth By Device

Discussion in 'Tomato Firmware' started by MrTea, Apr 21, 2009.

  1. MrTea

    MrTea Addicted to LI Member

    First the issue...
    I want to collect bandwidth stats for each device linked to my router. I don't care if it is collected by ip, mac address, or port number. I want graphs and data displays similar to what is currently in tomato. ie: real-time, daily, weekly, etc. I would like this data to be collected on the router, and then, at certain specified intervals, saved to a cifs path. Second best would be a collection program running on one of my computers, getting the data from the router. Third best is a collection program running on a computer, getting data from all other computers, bypassing the router completely.

    My *ware...
    This is a home network, running a mix of wired and wireless connections.
    I have a linksys WRT54G v 2.0 and am using tomato 1.23. All of the computers connected to the router run windows xp.

    What I've done so far...
    I have looked a lots of threads, here and there, that are asking basically the same as I am. I have also visited several web pages where "solutions" are given.

    My conclusions...
    Short of modifying tomato, it seems that the solution will require one computer to collect the information. I was able to set up snmp on the router. Then I installed and ran mrtg on my computer, collecting data from the router. It looks like this is only going to give me the same stats I currently get from tomato.

    My questions...
    1. Is my conclusion accurate? If not, how can I make it work?
    2. If I have to collect these stats outside of the router...
    A. since all boxes run XP, it looks like it might be easier to use wmi to collect stats instead of snmp. Any thoughts here?
    B. if wmi is recommended, do you know of any free and simple programs that will collect and display the data I need.

    Thank for any help!
  2. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    I think the Victek Tomato mod does exactly as you desire.
  3. MrTea

    MrTea Addicted to LI Member

    I went to the Victek mod site and I didn't see anything that listed the differences between a standard tomato and a Victek tomato. I looked at the demo and (based on that) it looks like this mod will only allow me to limit bandwidth by ip. I want to monitor the bandwidth, not limit it.

    If I have misunderstood what this does, then I am eager to try it out.

  4. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    It seems that with Victek's mod, you need to add some lines to the Tomato Firewall script, but it's entirely feasible to have per-device bandwidth graphs. I've never done it myself, so I can't give a blow-by-blow howto, but just search this forum for "imq1". There should be several posts with examples on what to do.
  5. tonysa13

    tonysa13 Addicted to LI Member

    I've been trying to do exactly what you're looking to do, and I'm surprised not to have found a solution out there...

    So far, I've been able to configure iptables on the router itself to collect bandwidth totals, but I have a few issues...

    First, under Administration->Scripts->Firewall, I add something like this:
    /usr/sbin/iptables -N Count
    /usr/sbin/iptables -I FORWARD -j Count
    /usr/sbin/iptables -A Count -d
    /usr/sbin/iptables -A Count -s

    You can tweek the IPs and masks, I ended up using Static DHCP to put devices from one roommate to IPs on, another's from 16-23, etc... (I'm trying to calculate how much bandwidth each roommate is using)

    So, the rules above will count bytes sent to and from any IP to 15. I can see the counts by running this command while SSH'd into the router:

    # iptables -L Count -nvx
    Chain Count (1 references)
    pkts bytes target prot opt in out source destination
    19939 23189156 0 -- * *
    11911 1219109 0 -- * *

    The issues I have are:
    1- the iptables gets zeroed out at various times during the day, and I cannot figure out what causes them to get cleared
    2- I need a script to run frequently that will parse the output of the iptables command, and save the byte counts somewhere... and then zero out the tables...
    3- I need to transfer the data off of the router, or get some fancy graphs showing the data in the GUI...

    Anyways, that's as far as I've gotten, hope this helps you. It's definitely seems possible to be able to collect the data, and I'm surprised that it hasn't been done yet.

    If anyone can take this and get farther with it, I'd be very grateful for shared solutions... :)

  6. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    Performing the search I mentioned in my previous post, I saw several people getting it to work, along with screenshots of the graphs...
  7. Hypernova

    Hypernova LI Guru Member

    1) The iptable stats are reset when the firewall resets, this happens when ever you configure QoS, WAN reset (say when the phone line jigges a little and your modem resyncs).
    2) iptables -L "chain" > location/filename IIRC, I also experimented with a small programme that pulled the numbers out of the stored output and tried to keep count on a CIFS location. you can have the code if you want, it's horrible to look at though. for example the line that grabe the numbers from the -L output looks like:
    while (fscanf(saved, "%lld %s %lld %lld %lld %lld", &pkts, source, &bytes_1, &bytes_2, &bytes_3, &bytes_4) != EOF)

    X-WRT appears to have the counter per-IP ability, with daily graphs to boot.
  8. Toastman

    Toastman Super Moderator Staff Member Member

    The search function on the forum isn't working for me, so this is all I can find about the IMQ mod using google.

    Try this script:

    modprobe imq
    modprobe ipt_IMQ
    ip link set imq1 up
    iptables -t mangle -A POSTROUTING -d yyy.yyy.yyy -j IMQ --todev 1
    ip link set imq1 up
    iptables -t mangle -A PREROUTING -s yyy.yyy.yyy -j IMQ --todev 1
    ip link set imq2 up
    iptables -t mangle -A POSTROUTING -d yyy.yyy.yyy -j IMQ --todev 2
    ip link set imq2 up
    iptables -t mangle -A PREROUTING -s yyy.yyy.yyy -j IMQ --todev 2

    Then look at realtime graph... It's possible to label the graphs with a name instead of IMQ number. Victek mod will allow up to 16.

    To store the data and collect it elsewhere needs more. You might find what you need here:http://www.linksysinfo.org/forums/showthread.php?t=52860

Share This Page