Allow the plugins to return the results as a tuple or list
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 24 May 2015 10:48:53 +0000 (10:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 24 May 2015 10:48:53 +0000 (10:48 +0000)
Therefore we do not have the necessity to format the result
into a format that rrdtool can parse later.

src/collecty/plugins/base.py
src/collecty/plugins/conntrack.py
src/collecty/plugins/cpu.py
src/collecty/plugins/disk.py
src/collecty/plugins/interface.py
src/collecty/plugins/latency.py
src/collecty/plugins/loadavg.py
src/collecty/plugins/memory.py

index a2c1055..6c31ede 100644 (file)
@@ -155,6 +155,9 @@ class Plugin(threading.Thread):
                        now = datetime.datetime.utcnow()
                        try:
                                result = o.collect()
+
+                               if isinstance(result, tuple) or isinstance(result, list):
+                                       result = ":".join(("%s" % e for e in result))
                        except:
                                self.log.warning(_("Unhandled exception in %s.collect()") % o, exc_info=True)
                                continue
index cbfece9..0e1c6d9 100644 (file)
@@ -414,7 +414,7 @@ class ConntrackLayer3ProtocolsObject(ConntrackObject):
                        r = self.conntrack_table.layer3_protocols.get(proto, 0)
                        results.append("%s" % r)
 
-               return ":".join(results)
+               return results
 
 
 class ConntrackLayer4ProtocolsObject(ConntrackObject):
@@ -435,7 +435,7 @@ class ConntrackLayer4ProtocolsObject(ConntrackObject):
                        r = self.conntrack_table.layer4_protocols.get(proto, 0)
                        results.append("%s" % r)
 
-               return ":".join(results)
+               return results
 
 
 class ConntrackProtocolWithStatesObject(ConntrackObject):
@@ -464,7 +464,7 @@ class ConntrackProtocolWithStatesObject(ConntrackObject):
                return results
 
        def collect(self):
-               return ":".join(self.get_states())
+               return self.get_states()
 
 
 class ConntrackPlugin(base.Plugin):
index 292bf0c..962163f 100644 (file)
@@ -137,7 +137,7 @@ class ProcessorObject(base.Object):
                                if len(columns) < 8:
                                        continue
 
-                               entry = [
+                               return (
                                        columns[1], # user
                                        columns[2], # nice
                                        columns[3], # sys
@@ -145,9 +145,7 @@ class ProcessorObject(base.Object):
                                        columns[5], # wait
                                        columns[6], # irq
                                        columns[7], # sirq
-                               ]
-
-                               return ":".join(entry)
+                               )
                finally:
                        if f:
                                f.close()
index b5a2346..759156c 100644 (file)
@@ -196,7 +196,7 @@ class DiskObject(base.Object):
        def collect(self):
                stats = self.parse_stats()
 
-               return ":".join((
+               return (
                        self.is_awake(),
                        stats.get("read_ios"),
                        stats.get("read_sectors"),
@@ -204,7 +204,7 @@ class DiskObject(base.Object):
                        stats.get("write_sectors"),
                        self.get_bad_sectors(),
                        self.get_temperature(),
-               ))
+               )
 
        def parse_stats(self):
                """
index c373cf2..addca19 100644 (file)
@@ -268,7 +268,7 @@ class InterfaceObject(base.Object):
                                if f:
                                        f.close()
 
-               return ":".join(ret)
+               return ret
 
 
 class InterfacePlugin(base.Plugin):
index a6db8d0..0b2324a 100644 (file)
@@ -112,11 +112,11 @@ class LatencyObject(base.Object):
                                % { "host" : self.hostname, "msg" : e.msg })
                        return
 
-               return ":".join((
+               return (
                        "%.10f" % ping.avg_time,
                        "%.10f" % ping.loss,
                        "%.10f" % ping.stddev,
-               ))
+               )
 
 
 class LatencyPlugin(base.Plugin):
index c7e5e14..24cce74 100644 (file)
@@ -84,7 +84,7 @@ class LoadAvgObject(base.Object):
                return "default"
 
        def collect(self):
-               return ":".join(["%.10f" % l for l in os.getloadavg()])
+               return os.getloadavg()
 
 
 class LoadAvgPlugin(base.Plugin):
index 7fcf115..55d6586 100644 (file)
@@ -132,7 +132,7 @@ class MemoryObject(base.Object):
                        else:
                                ret.append("0")
 
-                       return ":".join(ret)
+                       return ret
                finally:
                        if f:
                                f.close()