scripts/deletestats.py: Delete netif stats after 21 days

This adds an additional config value to set the deletion threshold
for netif data.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2018-01-14 20:58:00 +01:00
parent 59fcf2fa8f
commit 804ce80472
2 changed files with 3 additions and 1 deletions

View File

@ -8,6 +8,7 @@ CONFIG = {
"orphan_threshold_days": 7, # Router switches to orphaned state after X days
"delete_threshold_days": 180, # Router is deleted after X days
"router_stat_days": 30, # Router stats are collected for X days (if online)
"router_stat_netif": 21, # Router stats for netifs are collected for X days (if online)
"router_stat_mindiff_secs": 10, # Time difference (uptime) in seconds required for a new entry in router stats
"router_stat_mindiff_default": 270, # Time difference (router stats tables) in seconds required for a new entry in router stats
"router_stat_mindiff_netif": 570, # Time difference (router netif stats) in seconds required for a new entry in router stats

View File

@ -387,6 +387,7 @@ def delete_unlinked_routers(mysql):
def delete_old_stats(mysql):
threshold=(utcnow() - datetime.timedelta(days=CONFIG["router_stat_days"])).timestamp()
threshold_netif=(utcnow() - datetime.timedelta(days=CONFIG["router_stat_netif"])).timestamp()
start_time = time.time()
mysql.execute("""
@ -427,7 +428,7 @@ def delete_old_stats(mysql):
LEFT JOIN router AS r ON s.router = r.id
SET s.deletebit = 1
WHERE s.time < %s AND (r.status = 'online' OR r.status IS NULL)
""",(threshold,))
""",(threshold_netif,))
mysql.commit()
writelog(CONFIG["debug_dir"] + "/deletetime.txt", "Update netif stats: %.3f seconds" % (time.time() - start_time))
print("--- Update netif stats: %.3f seconds ---" % (time.time() - start_time))