Retrieving real-time bandwidth stats

Discussion in 'Tomato Firmware' started by bleepy, Apr 15, 2010.

  1. bleepy

    bleepy Networkin' Nut Member

    Hi there,

    I am looking to retrieve the real-time bandwidth stats from Tomato, to use in another web-application to show total network traffic routed via it.

    However, Tomato's output on Real-Time is not a static output, and this creates a problem. I have tried looking through all the source, but can't find a way to retrieve it. There are many files used on the bandwidth monitor page, so maybe I'm just missing something?

    I am able to connect via any method to whatever page on the web interface, or even via telnet/ssh in order to achieve this.

    I would be grateful for any response or indication on how to gain the current, live bandwidth usage.

  2. rhester72

    rhester72 Network Guru Member

    The web code is pulling the data directly from the /proc filesystem on a per-interface basis. You can use a similar approach and potentially aggregate the interfaces if necessary, or roll your own solution with libpcap to do something similar if you require any sort of filtering.

  3. bleepy

    bleepy Networkin' Nut Member

    Thanks for the reply.

    Forgive me for my lack of knowledge, but what exactly should I be looking at? Is it a specific file, or something else? There doesn't appear to be many commands available, and a lot either give 'unknown', or 'permission denied'.

  4. rhester72

    rhester72 Network Guru Member

    It's not a command. He is parsing the raw kernel stats that are exposed via the /proc filesystem.

    They are absolute values, so you have to do the derivation yourself on a per-interface basis.

    In short: This isn't a web project as much as it is a code-development (almost certainly in C, though it *could* be done in something else) project with a web component.

  5. mstombs

    mstombs Network Guru Member

  6. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    You can get the bw data with a request to update.cgi with POST data:
    Response comes in the form of (sample data from a request I just performed):
    netdev={ 'eth0':{rx:0x9c55b530,tx:0xbf8a5d3f},'eth1':{rx:0xb5257dac,tx:0x7cb3f92f},'br0':{rx:0x814d4b6f,tx:0x6ed2070d},'tun21':{rx:0x0,tx:0x0},'vlan0':{rx:0x7a676,tx:0x21e9b7a},'vlan1':{rx:0x2cac0321,tx:0x23636e6}};
    For what it's worth, I just tried it as a GET request and it also works:
  7. bleepy

    bleepy Networkin' Nut Member

    Brilliant, working with the output now. Although, I can't seem to calculate it into a number that's even close to what the bandwidth monitor is showing.
  8. bleepy

    bleepy Networkin' Nut Member

    All sorted, just realised it's an increasing 'counter' - just taken two samples at 1 second intervals, and calculated the difference.

    Thanks for everyone's help!
  9. rhester72

    rhester72 Network Guru Member

    Neat! I had no idea this was exposed through the CGI!

  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