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

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

[script] Current Download/Upload WAN speed

Discussion in 'Asuswrt-Merlin' started by berez, Jun 14, 2018.

Tags:
  1. berez

    berez Occasional Visitor

    Joined:
    Apr 26, 2016
    Messages:
    20
    Hi,

    is there possible to get information about current Download/Upload WAN speed? I would use bash script.
     
    Vexira likes this.
  2. Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!
  3. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,046
    Location:
    UK
    Probably. What sort of information do you want exactly?
     
  4. berez

    berez Occasional Visitor

    Joined:
    Apr 26, 2016
    Messages:
    20
    This speed value, or other similar current speed value...
     

    Attached Files:

  5. Martineau

    Martineau Very Senior Member

    Joined:
    Jul 8, 2012
    Messages:
    1,632
    Location:
    UK
    For download speed testing
    Code:
    curl  http://proof.ovh.net/files/100Mb.dat -w "%{time_connect},%{time_total},%{speed_download},%{http_code},%{size_download},%{url_effective}\n" -o /dev/null
    and while the above is useful when run interactively, you can suppress the progress indicator to have only the '.csv' result line returned for piping/parsing out to a file for later analysis using scripting:
    Code:
    curl  -s http://proof.ovh.net/files/100Mb.dat -w "%{time_connect},%{time_total},%{speed_download},%{http_code},%{size_download},%{url_effective}\n" -o /dev/null
    If you choose an appropriate Upload test site then the same technique can be used for Upload speed testing
     
  6. berez

    berez Occasional Visitor

    Joined:
    Apr 26, 2016
    Messages:
    20
    I want get current speed-stats. No possible speed. Example: if my PC #1 downoads current 1mbps and second PC is downloading now 2mbps then value have to shows 3mbps as current download speed from WAN.
     
  7. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,046
    Location:
    UK
    Speed is a function of time. So you have to decide what time period you are measuring, 1 millisecond, 1 second, 10 seconds, etc.

    This command will give you the total number of bytes downloaded and uploaded at that point in time. If you wait for your desired sampling period (say 1 second) and issue the command again you can subtract one from the other giving you the rate.

    Code:
    ifconfig $(nvram get wan0_ifname) | grep "RX bytes" | awk -F[:\(] '{print $2 $4}'
     
  8. berez

    berez Occasional Visitor

    Joined:
    Apr 26, 2016
    Messages:
    20
    Thanks - great solution.

    What is the best way to "transfer" these values to another debian-based device (rapsberry pi)?

    I see two solutions
    1. Install mosquito service on the router, and then "publish" (by mosquitto_pub command) values to rapsberry pi.

    or

    2. Create script on rapsberry pi, script will do:
    - logon to router by ssh
    - execute @ColinTaylor command


    maybe any other ideas?
     
  9. kfp

    kfp Very Senior Member

    Joined:
    Jun 26, 2014
    Messages:
    708
    Probably easier to use SNMP if you need this data on another device. Note that the RX+TX number on WAN interface (br0) would wrap after 4GB because Broadcom/Asus is funny that way.
     
  10. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,046
    Location:
    UK
    I'd never heard of mosquito so can't comment on that.

    I do something similar with QoS bandwidth data. I have a script that runs continuously on the router. Every 2 seconds it collects the data and appends it to a file together with a timestamp. Then I have another process that periodically runs on a Centos server that logs into the router with FTP and transfers the file. The file is fed into an RRD database and displayed as a graph on a web page.

    EDIT: @kfp suggestion is probably a better solution, although it's not appropriate in my specific situation :(.

    Whatever solution you choose should ultimately by driven by the data; frequency, format, accuracy, resilience, etc.
     
    Last edited: Jun 14, 2018
Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!