kennedyshead / aioasuswrt

MIT License
24 stars 24 forks source link

Use rstats data for daily and monthly traffic #77

Open serverwentdown opened 3 years ago

serverwentdown commented 3 years ago

To obtain the data, the following command can be issued:

killall -USR2 rstats  # This asks rstats to create a JS file at `/var/spool/rstats-history.js`

Afterwards, the file at /var/spool/rstats-history.js can be read. Example contents:

daily_history = [
[0x790418,0x8f9bea0,0x90b8374],[0x790419,0x16c6f68,0x32d5ca9],[0x79041a,0x1435521,0x17f6c63],[0x79041b,0x8c97980,0xa1a4b10],[0x79041c,0x15c8771,0x150b02c],[0x79041d,0x3a6c971,0x7c0bf19],[0x79041e,0xd20a7c,0x861438],[0x79041f,0xf88093,0x1382069],[0x790501,0xc68ff6f,0xbabb5c5],[0x790502,0x1e0102b,0xfe4535],[0x790503,0x232246b,0x2a3a73b],[0x790504,0x1012b81c,0x103627bc],[0x790505,0xbf7317d,0xe576fdb],[0x790506,0x849a390,0x7b82ecc],[0x790507,0x91bb84b,0x879d320],[0x790508,0x91f9a53,0xcad3723],[0x790509,0xf4e0808,0x199dfe29],[0x79050a,0x5e40a39,0x5641d04]];

monthly_history = [
[0x790400,0x1b40d89d,0x22a23b79],[0x790500,0x5c3c2610,0x69bc8e0e]];

(The web interface deletes this file after reading it)

The data is in the format [date, rx, tx] where:

Alternative implementation

Instead, the statistics file at /var/lib/misc/rstats-history.gz can be read directly:

  1. Decompress the file
  2. Parse the raw bytes. They pretty much map to the above JavaScript almost exactly the same way (little endian), but the values are in bytes instead of kilobytes (/ 1024)

References

GPL_RT_AC1200GPlus_300438252272 / ... / release / src / router / rstats / rstats.c

serverwentdown commented 3 years ago

I'm willing to implement but first I want to get some comments from the community.

kennedyshead commented 2 years ago

I dag go for it :) it could be a nice addition to the package!