kennedyshead / aioasuswrt

MIT License
24 stars 24 forks source link

Simplified retrieving total rx and tx bytes #23

Closed wdullaer closed 5 years ago

wdullaer commented 5 years ago

Renamed async_get_packets_total to async_get_bytes_total to better represent what it is doing. This will require a change in the home-assistant sensor code, since it was part of the public API.

async_get_bytes_total now relies on async_get_rx and async_get_tx

Removed cache parameter from async_get_rx and async_get_tx; it was not used and async_get_bytes_total is already doing caching

Make async_get_rx and async_get_tx return integers

Fixes #21

There seems to be an issue where the counters on my router are reset every 12 hours. According to the kernel documentation, this should not happen (counters are only reset on reboot or when the interface module is unloaded). A potential further improvement could be to pass in the name of the interface, so we can expose more sensors (WAN traffic, WLAN traffic, Guest wifi traffic etc)

kennedyshead commented 5 years ago

Nice!

wdullaer commented 5 years ago

I figured out why the bytes are resetting every now and then. I noticed (through the home-assistant log) that the reset happens around 4.3 GB, which happens to be 2^32-1, the max value of an unsigned 32 int. So my router kernel is using an unsigned int to count the bytes which essentially overflows and loops around to zero. Unless I find some other field to look at (which I doubt), we will only be able to accurately report on total data transfer by keeping some additional state somewhere else. All of this is on an RT-N66U, hopefully newer routers have a 64 bit architecture and use a 64 bit int for the counters

kennedyshead commented 5 years ago

I figured out why the bytes are resetting every now and then. I noticed (through the home-assistant log) that the reset happens around 4.3 GB, which happens to be 2^32-1, the max value of an unsigned 32 int. So my router kernel is using an unsigned int to count the bytes which essentially overflows and loops around to zero. Unless I find some other field to look at (which I doubt), we will only be able to accurately report on total data transfer by keeping some additional state somewhere else. All of this is on an RT-N66U, hopefully newer routers have a 64 bit architecture and use a 64 bit int for the counters

Yes, I think that an frontend hack might be the way to go in the future for this.

kennedyshead commented 5 years ago

https://travis-ci.org/kennedyshead/aioasuswrt

It was setup before :/

kennedyshead commented 5 years ago

You will have to create a new PR with that fix

wdullaer commented 5 years ago

For travis, I think you need to rename travis.yaml to .travis.yml

kennedyshead commented 5 years ago

It must have been changed at some point, its correctly named now