]> git.ipfire.org Git - collecty.git/commitdiff
Take running time of plugins into account when calculating interval.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Sep 2012 18:00:58 +0000 (18:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Sep 2012 18:00:58 +0000 (18:00 +0000)
collecty/plugins/base.py

index b29565726cc1f4096160fd3a226764d3cf99d95e..2997d11d74a05cc2931950e53b95672ee3bfd997 100644 (file)
@@ -253,13 +253,22 @@ class DataSource(threading.Thread):
                """
                        This method catches errors from the read() method and logs them.
                """
+               start_time = time.time()
+
                try:
-                       return self.read(*args, **kwargs)
+                       data = self.read(*args, **kwargs)
+                       if data is None:
+                               self.log.warning(_("Received empty data."))
+                       else:
+                               self.data.append("%d:%s" % (start_time, data))
 
                # Catch any exceptions, so collecty does not crash.
                except Exception, e:
                        self.log.critical(_("Unhandled exception in read()!"), exc_info=True)
 
+               # Return the elapsed time since _read() has been called.
+               return (time.time() - start_time)
+
        def _submit(self, *args, **kwargs):
                """
                        This method catches errors from the submit() method and logs them.
@@ -281,7 +290,9 @@ class DataSource(threading.Thread):
                        # Wait until the timer has successfully elapsed.
                        if self.timer.wait():
                                self.log.debug(_("Collecting..."))
-                               self._read()
+                               delay = self._read()
+
+                               self.timer.reset(delay)
 
                self._submit()
                self.log.debug(_("Stopped."))