]> git.ipfire.org Git - collecty.git/commitdiff
Tidy up collection and remove double-handling of unexpected exceptions
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Sep 2020 11:10:55 +0000 (11:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Sep 2020 11:10:55 +0000 (11:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/collecty/daemon.py
src/collecty/plugins/base.py

index cb811ffd82531680a3d6f9b73183427daa7f44fc..199e363963fab75954be753fa77dd84c64502700 100644 (file)
@@ -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):
                """
index fc00427f320ca8817a6264ac376a3cef6e176588..080db041c4bcea61c1dc14f8848f19c9fed1df78 100644 (file)
@@ -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):