From: Michael Tremer Date: Mon, 28 Sep 2020 11:10:55 +0000 (+0000) Subject: Tidy up collection and remove double-handling of unexpected exceptions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50ac7c3f9abf1d425a164f729c55c813629bb621;p=collecty.git Tidy up collection and remove double-handling of unexpected exceptions Signed-off-by: Michael Tremer --- diff --git a/src/collecty/daemon.py b/src/collecty/daemon.py index cb811ff..199e363 100644 --- a/src/collecty/daemon.py +++ b/src/collecty/daemon.py @@ -115,12 +115,7 @@ class Collecty(object): self._schedule_plugin(plugin) # Run collection - try: - plugin.collect() - - except Exception as e: - log.error("Unhandled exception in %s" % plugin, exc_info=True) - return + plugin.collect() def _commit(self): """ diff --git a/src/collecty/plugins/base.py b/src/collecty/plugins/base.py index fc00427..080db04 100644 --- a/src/collecty/plugins/base.py +++ b/src/collecty/plugins/base.py @@ -147,25 +147,30 @@ class Plugin(object, metaclass=PluginRegistration): time_start = time.time() # Run through all objects of this plugin and call the collect method. - for o in self.objects: + for object in self.objects: now = datetime.datetime.utcnow() + + # Run collection try: - result = o.collect() + result = object.collect() - result = self._format_result(result) - except: - self.log.warning(_("Unhandled exception in %s.collect()") % o, exc_info=True) + # Catch any unhandled exceptions + except Exception as e: + self.log.warning(_("Unhandled exception in %s.collect()") % object, exc_info=True) continue if not result: - self.log.warning(_("Received empty result: %s") % o) + self.log.warning(_("Received empty result: %s") % object) continue - self.log.debug(_("Collected %s: %s") % (o, result)) + # Format the result for RRDtool + result = self._format_result(result) + + self.log.debug(_("Collected %s: %s") % (object, result)) # Add the object to the write queue so that the data is written # to the databases later. - self.collecty.write_queue.add(o, now, result) + self.collecty.write_queue.add(object, now, result) # Returns the time this function took to complete. delay = time.time() - time_start @@ -173,6 +178,8 @@ class Plugin(object, metaclass=PluginRegistration): # Log some warning when a collect method takes too long to return some data if delay >= 60: self.log.warning(_("A worker thread was stalled for %.4fs") % delay) + else: + self.log.debug(_("Collection finished in %.2fms") % (delay * 1000)) @staticmethod def _format_result(result):