From a79ddc49c687e15ce054b38d8d5df37c3a510488 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 9 Jan 2018 13:35:54 +0100 Subject: [PATCH] improve statistics --- boswatch/plugin/plugin.py | 41 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/boswatch/plugin/plugin.py b/boswatch/plugin/plugin.py index 62dc0e1..72f3998 100644 --- a/boswatch/plugin/plugin.py +++ b/boswatch/plugin/plugin.py @@ -26,17 +26,17 @@ class Plugin: _pluginsActive = 0 def __init__(self, pluginName): - """!init preload some needed locals - and then call onLoad() directly""" + """!init preload some needed locals and then call onLoad() directly""" self._pluginName = pluginName logging.debug("load %s", self._pluginName) self._pluginsActive += 1 # for time counting + self._sumTime = 0 self._setupTime = 0 self._alarmTime = 0 self._teardownTime = 0 - self._endTime = 0 + self._tmpTime = 0 # for statistics self._runCount = 0 @@ -58,11 +58,14 @@ class Plugin: logging.debug("- alarm errors %d", self._alarmErrorCount) logging.debug("- teardown errors %d", self._teardownErrorCount) + def _loadConfig(self): + pass + def _run(self, bwPacket): self._runCount += 1 logging.debug("[%s] run #%s", self._pluginName, self._runCount) - self._setupTime = time.time() + self._tmpTime = time.time() try: logging.debug("[%s] setup", self._pluginName) self.setup() @@ -70,7 +73,8 @@ class Plugin: self._setupErrorCount += 1 logging.exception("[%s] error in setup", self._pluginName) - self._alarmTime = time.time() + self._setupTime = time.time() - self._tmpTime + self._tmpTime = time.time() try: logging.debug("[%s] alarm", self._pluginName) self.alarm(bwPacket) @@ -78,7 +82,8 @@ class Plugin: self._alarmErrorCount += 1 logging.exception("[%s] error in alarm", self._pluginName) - self._teardownTime = time.time() + self._alarmTime = time.time() - self._tmpTime + self._tmpTime = time.time() try: logging.debug("[%s] teardown", self._pluginName) self.teardown() @@ -86,11 +91,27 @@ class Plugin: self._teardownErrorCount += 1 logging.exception("[%s] error in teardown", self._pluginName) + self._teardownTime = time.time() - self._tmpTime + self._sumTime = self._setupTime + self._alarmTime + self._teardownTime + self._endTime = time.time() - logging.debug("[%s] took %0.2f seconds", self._pluginName, self._endTime - self._setupTime) - logging.debug("- setup: %0.2f sec.", self._alarmTime - self._setupTime) - logging.debug("- alarm: %0.2f sec.", self._teardownTime - self._alarmTime) - logging.debug("- teardown: %0.2f sec.", self._endTime - self._teardownTime) + logging.debug("[%s] took %0.3f seconds", self._pluginName, self._sumTime) + logging.debug("- setup: %0.2f sec.", self._setupTime) + logging.debug("- alarm: %0.2f sec.", self._alarmTime) + logging.debug("- teardown: %0.2f sec.", self._teardownTime) + + def _getStatistics(self): + """!Returns statistical information's from last plugin run + + @return Count of runs complete + @return time of last complete run + @return time of last setup + @return time of last alarm + @return time of last teardown + @return count of setup errors complete + @return count of alarm errors complete + @return count of teardown errors complete""" + return self._runCount, self._sumTime, self._setupTime, self._alarmTime, self._teardownTime, self._setupErrorCount, self._alarmErrorCount, self._teardownErrorCount def onLoad(self): """!Called by import of the plugin