Delete old router events

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2017-11-10 13:59:16 +01:00
parent 5262a4e14f
commit 9a32c7bffd
1 changed files with 16 additions and 0 deletions

View File

@ -20,6 +20,7 @@ CONFIG = {
"offline_threshold_minutes": 20,
"orphan_threshold_days": 120,
"router_stat_days": 7,
"event_num_entries": 20,
}
router_rate_limit_list = {}
@ -288,6 +289,21 @@ def delete_old_stats(mysql):
WHERE time < %s
""",(threshold,))
events = mysql.fetchall("""
SELECT router, COUNT(time) AS count FROM router_events
GROUP BY router
""")
for e in events:
delnum = int(e["count"] - CONFIG["event_num_entries"])
if delnum > 0:
mysql.execute("""
DELETE FROM router_events
WHERE router = %s
ORDER BY time ASC
LIMIT %s
""",(e["router"],delnum,))
mysql.commit()
def events_append(mysql,router_id,event,comment):