save router run stats to stats file

This commit is contained in:
Bastian Schroll 2019-10-25 14:33:18 +02:00
parent 9a33975f52
commit 1f01aaf2c3
No known key found for this signature in database
GPG key ID: 0AE96912A20E9F5F
2 changed files with 22 additions and 0 deletions

1
.gitignore vendored
View file

@ -10,6 +10,7 @@
\venv/
# generated files
stats_*
log/
docu/docs/api/html
docu/site/

View file

@ -18,6 +18,7 @@
# todo think about implement threading for routers and the plugin calls (THREAD SAFETY!!!)
import logging
import importlib
import time
from boswatch.configYaml import ConfigYAML
from boswatch.router.router import Router
from boswatch.router.route import Route
@ -30,6 +31,7 @@ class RouterManager:
def __init__(self):
"""!Create new router"""
self._routerDict = {}
self._startTime = int(time.time())
def __del__(self):
"""!Destroy the internal routerDict
@ -115,6 +117,8 @@ class RouterManager:
else:
logging.warning("unknown router: %s", routerName)
self._saveStats() # write stats to stats file
def _showRouterRoute(self):
"""!Show the routes of all routers"""
for name, routerObject in self._routerDict.items():
@ -123,3 +127,20 @@ class RouterManager:
for routePoint in routerObject.routeList:
counter += 1
logging.debug(" %d. %s", counter, routePoint.name)
def _saveStats(self):
lines = []
for name, routerObject in self._routerDict.items():
lines.append("[" + name + "]")
lines.append("loaded route points: " + str(len(routerObject.routeList)))
for routePoint in routerObject.routeList:
lines.append("[+] " + routePoint.name)
if routePoint.statistics:
if routePoint.statistics()['type'] == "plugin":
lines.append(" Runs: " + str(routePoint.statistics()['runCount']))
lines.append("")
with open("stats_" + str(self._startTime) + ".txt", "w") as stats:
for line in lines:
stats.write(line + "\n")