What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Getting Traffic Monitor Values Programmatically

macdis

Occasional Visitor
I'm wondering if it's possible to retrieve Traffic Monitor throughput data programmatically (MB/s, see screenshot).

I can retrieve the data via a series of curl calls, but is there is a simpler way to retrieve it?

My current method is ok, I guess, but clunky. Basically, it's as follows:

1. Get the login_authorization token (hashed username+password) via Chrome dev tools. This only has to be done once and can be reused until you change your username or password.
2. curl login.cgi, using the login_authorization token to get the asus_token session cookie.
3. curl update.cgi using the asus_token session cookie to retrieve the data. Since the data is cumulative and measured in bytes, this step has to be done twice to calculate a transfer rate in bytes/second. The retrieved data is of the following form, which indicates cumulative byte values in hex:
Code:
netdev = {
 'BRIDGE':{rx:0xb37d3bc3c0,tx:0x933c86706a}
,'INTERNET':{rx:0x58aea7d5e2,tx:0x75cae6fe6e}
,'WIRED':{rx:0xde923a8334,tx:0xbe071d1285}
,'WIRELESS0':{rx:0x1f4490,tx:0xd208abd}
,'WIRELESS1':{rx:0x1d46764,tx:0xd9824ce}
,'LACP1':{rx:0x38d8681136,tx:0x1cb1e05be1}
,'LACP2':{rx:0x905d616b46,tx:0x8ca6fe4c7e}
}
4. Logout via curl.
5. Do the math (to convert cumulative bytes to Mb/s or whatever).

(I basically adapted the above process from a sort of unrelated but interesting tutorial on a now dead website. Here's the wayback machine link, if anyone's interested.)

I don't think it matters much, but I have an RT-AX88U running 3004.388.8_4.

Thanks!

img.png
 
Last edited:
Assuming that eth0 is the WAN interface (it is, isn't it?), I am realizing that I can probably also do this via

Code:
ssh me@router 'cat /sys/class/net/eth0/statistics/rx_bytes'
ssh me@router 'cat /sys/class/net/eth0/statistics/tx_bytes'
 
Been asking same question to myself couple of days ago. Ended up trying the following with my gt-ax6000 3004.388.8_4 :

https://github.com/Vaskivskyi/asusrouter
AsusData.NETWORK returns the following structure:

Code:
{'wan': {'rx': 396035939110, 'tx': 111527332367, 'rx_speed': 0.0, 'tx_speed': 0.0}, 'wired': {'rx': 9806726476, 'tx': 60173605806, 'rx_speed': 0.0, 'tx_speed': 0.0}, 'bridge': {'rx': 108797187644, 'tx': 395545353415, 'rx_speed': 0.0, 'tx_speed': 0.0}, '2ghz': {'rx': 238424661, 'tx': 2586632521, 'rx_speed': 0.0, 'tx_speed': 0.0}, '5ghz': {'rx': 60846630938, 'tx': 360517350768, 'rx_speed': 0.0, 'tx_speed': 0.0}, 'usb': {'rx': 0, 'tx': 0, 'rx_speed': 0.0, 'tx_speed': 0.0}}

for some reason rx_speed/tx_spedd stay constantly at 0. Going to to play with throughput calculation based on total bytes of tx/rx. Additionally refresh rate of api is not what I expected or my python skills are not enough.
 
And a tool like Beszel provides an at-a-glance monitoring solution for a bunch of stuff, including send/receive speeds, accessible through a web UI or Pocketbase web API, email notifications, and blah blah blah. Might be useful in some situations. Has to be installed manually to jffs and started via the services-start script. The WAN interface can be selected at startup.
 
If you're looking for router totals (not individual interfaces), vnStat does that (incorporated into vnStat-on-Merlin: https://www.snbforums.com/goto/post?id=677569). The underlying program vnStat has several options, including -l (dash el) to capture live usage.
 

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top