Global stats put into separate scripts and run by cron

Most of the processes is executed every five minutes, but
deleting can be done only once per day ...

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2017-11-16 12:14:17 +01:00
parent 50445edb79
commit a65873c2ee
4 changed files with 69 additions and 6 deletions

View File

@ -87,12 +87,12 @@ def alfred():
import_nodewatcher_xml(mysql, mac, xml)
mysql.commit()
r.headers['X-API-STATUS'] = "ALFRED data imported"
detect_offline_routers(mysql)
delete_orphaned_routers(mysql)
delete_old_stats(mysql)
record_global_stats(mysql)
record_hood_stats(mysql)
update_mapnik_csv(mysql)
#detect_offline_routers(mysql)
#delete_orphaned_routers(mysql)
#delete_old_stats(mysql)
#record_global_stats(mysql)
#record_hood_stats(mysql)
#update_mapnik_csv(mysql)
mysql.close()
#pr.disable()
#s = io.StringIO()

26
scripts/calcglobalstats.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/python3
# Execute every 5 min, 2 mins after alfred comes in (sleep 120 in cron)
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
from ffmap.routertools import *
from ffmap.maptools import *
from ffmap.mysqltools import FreifunkMySQL
from ffmap.stattools import record_global_stats, record_hood_stats
import time
start_time = time.time()
mysql = FreifunkMySQL()
detect_offline_routers(mysql)
delete_orphaned_routers(mysql)
#delete_old_stats(mysql) # Only execute once daily, takes 2 minutes
record_global_stats(mysql)
record_hood_stats(mysql)
update_mapnik_csv(mysql)
mysql.close()
print("--- %s seconds ---" % (time.time() - start_time))

19
scripts/deletestats.py Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/python3
# Execute once daily, also 2 min after full 5 mins (so it does not coincide with alfred)
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
from ffmap.routertools import delete_old_stats
from ffmap.mysqltools import FreifunkMySQL
import time
start_time = time.time()
mysql = FreifunkMySQL()
delete_old_stats(mysql)
mysql.close()
print("--- %s seconds ---" % (time.time() - start_time))

18
scripts/setupcron.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/sh
monpath=/data/fff/fff-monitoring
if crontab -l | grep -q "$monpath" ; then
echo "Cron already set."
exit 1
fi
# Runs every 5 min and waits 2 min
(crontab -l 2>/dev/null; echo "2-59/5 * * * * $monpath/scripts/calcglobalstats.py") | crontab -
# Runs at 4:02
(crontab -l 2>/dev/null; echo "2 4 * * * $monpath/scripts/deletestats.py") | crontab -
echo "Cron set successfully."
exit 0