api/alfred: Change calculation of rx/tx after reboot
Previously, on restart the traffic of the last period before the restart was reused. Now, we use the logged traffic divided by the uptime. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
effcdf0a39
commit
55f81c4295
|
@ -447,7 +447,7 @@ def calculate_network_io(mysql, router_id, uptime, router_update):
|
|||
router: old router dict
|
||||
router_update: new router dict (which will be updated with new data)
|
||||
"""
|
||||
results = mysql.fetchall("SELECT netif, rx_bytes, tx_bytes, rx, tx FROM router_netif WHERE router = %s",(router_id,));
|
||||
results = mysql.fetchall("SELECT netif, rx_bytes, tx_bytes FROM router_netif WHERE router = %s",(router_id,));
|
||||
|
||||
with suppress(KeyError, StopIteration):
|
||||
if uptime < router_update["sys_uptime"]:
|
||||
|
@ -462,8 +462,8 @@ def calculate_network_io(mysql, router_id, uptime, router_update):
|
|||
else:
|
||||
for row in results:
|
||||
netif_update = next(filter(lambda n: n["name"] == row["netif"], router_update["netifs"]))
|
||||
netif_update["traffic"]["rx"] = int(row["rx"])
|
||||
netif_update["traffic"]["tx"] = int(row["tx"])
|
||||
netif_update["traffic"]["rx"] = int(netif_update["traffic"]["rx_bytes"] / router_update["sys_uptime"])
|
||||
netif_update["traffic"]["tx"] = int(netif_update["traffic"]["tx_bytes"] / router_update["sys_uptime"])
|
||||
|
||||
return uptime
|
||||
|
||||
|
|
Loading…
Reference in New Issue