]> git.ipfire.org Git - oddments/collecty.git/commitdiff
Update plugins to adapt the recent changes.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Sep 2012 18:19:59 +0000 (18:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Sep 2012 18:19:59 +0000 (18:19 +0000)
collecty/plugins/base.py
collecty/plugins/cpu.py
collecty/plugins/entropy.py
collecty/plugins/interface.py
collecty/plugins/loadavg.py
collecty/plugins/memory.py

index 2997d11d74a05cc2931950e53b95672ee3bfd997..8f67a3c7e9bc69c465bd8e8745f50ada065360b5 100644 (file)
@@ -305,13 +305,6 @@ class DataSource(threading.Thread):
                if self.timer:
                        self.timer.cancel()
 
                if self.timer:
                        self.timer.cancel()
 
-       @property
-       def now(self):
-               """
-                       Returns the current timestamp in the UNIX timestamp format (UTC).
-               """
-               return int(time.time())
-
 
 class GraphTemplate(object):
        # A unique name to identify this graph template.
 
 class GraphTemplate(object):
        # A unique name to identify this graph template.
index 978d8f91341bfa728e61d2658897cf0ff99e181b..3ba107999111cf6c6ea33439212d1813de6a0891 100644 (file)
@@ -85,21 +85,20 @@ class GraphTemplateCPU(base.GraphTemplate):
                "GPRINT:sirqmin:%12s\:" % _("Minimum") + " %6.2lf",
                "GPRINT:sirqavg:%12s\:" % _("Average") + " %6.2lf\\n",
 
                "GPRINT:sirqmin:%12s\:" % _("Minimum") + " %6.2lf",
                "GPRINT:sirqavg:%12s\:" % _("Average") + " %6.2lf\\n",
 
-#              "STACK:idle#ffff00:%-15s" % _("Idle"),
-#              "VDEF:idlemin=idle,MINIMUM",
-#              "VDEF:idlemax=idle,MAXIMUM",
-#              "VDEF:idleavg=idle,AVERAGE",
-#              "GPRINT:idlemax:%12s\:" % _("Maximum") + " %6.2lf" ,
-#              "GPRINT:idlemin:%12s\:" % _("Minimum") + " %6.2lf",
-#              "GPRINT:idleavg:%12s\:" % _("Average") + " %6.2lf\\n",
+               "STACK:idle#EFEFEF:%-15s" % _("Idle"),
+               "VDEF:idlemin=idle,MINIMUM",
+               "VDEF:idlemax=idle,MAXIMUM",
+               "VDEF:idleavg=idle,AVERAGE",
+               "GPRINT:idlemax:%12s\:" % _("Maximum") + " %6.2lf" ,
+               "GPRINT:idlemin:%12s\:" % _("Minimum") + " %6.2lf",
+               "GPRINT:idleavg:%12s\:" % _("Average") + " %6.2lf\\n",
        ]
 
        rrd_graph_args = [
                "--title", _("CPU usage"),
        ]
 
        rrd_graph_args = [
                "--title", _("CPU usage"),
-               "--vertical-label", _("Percent"),
+               "--vertical-label", _("Jiffies"),
 
 
-               # This can never be more than 100 percent.
-               #"--lower-limit", "0", "--upper-limit", "100",
+               "--lower-limit", "0", "--rigid",
        ]
 
 
        ]
 
 
@@ -151,17 +150,7 @@ class DataSourceCPU(base.DataSource):
                                        columns[7], # sirq
                                ]
 
                                        columns[7], # sirq
                                ]
 
-                               full = sum([int(e) for e in entry])
-
-                               for i in range(len(entry)):
-                                       entry[i] = int(entry[i]) * 100
-                                       entry[i] = "%s" % (entry[i] / full)
-
-                               entry.insert(0, "%s" % self.now)
-
-                               self.data.append(":".join(entry))
-                               break
-
+                               return ":".join(entry)
                finally:
                        if f:
                                f.close()
                finally:
                        if f:
                                f.close()
index da2076e41e52786e9d313f10436a63fe406665bc..1bf5f5ffb9e4fa5ba912207ed3cf915e7fc29139 100644 (file)
@@ -72,11 +72,13 @@ class DataSourceEntropy(base.DataSource):
                return cls(collecty, **kwargs)
 
        def read(self):
                return cls(collecty, **kwargs)
 
        def read(self):
-               data = "%s" % self.now
+               f = None
 
 
-               f = open(ENTROPY_FILE)
-               entropy = f.readline()
-               f.close()
+               try:
+                       f = open(ENTROPY_FILE)
+                       entropy = f.readline()
 
 
-               data += ":%s" % entropy.strip()
-               self.data.append(data)
+                       return entropy.strip()
+               finally:
+                       if f:
+                               f.close()
index 23868637eaef52ebe0b34b3e8f3c04fcb636861d..1e9703a0a7a57666e95a875d4bb89cfc81d69c37 100644 (file)
@@ -29,156 +29,172 @@ from ..i18n import _
 
 SYS_CLASS_NET = "/sys/class/net"
 
 
 SYS_CLASS_NET = "/sys/class/net"
 
-class GraphTemplateInterfaceBytes(base.GraphTemplate):
-       name = "interface-bytes"
-
-       rrd_graph = [
-               "DEF:bytes_rx=%(file)s:bytes_rx:AVERAGE",
-               "DEF:bytes_tx=%(file)s:bytes_tx:AVERAGE",
-
-               # Convert everything into bits.
-               "CDEF:bits_rx=bytes_rx,8,*",
-               "CDEF:bits_tx=bytes_tx,8,*",
-
-               # Invert the transmitted bytes to create upside down graph.
-               "CDEF:bits_tx_inv=bits_tx,-1,*",
-
-               # Compute the total bandwidth.
-               "CDEF:bits=bits_rx,bits_tx,+",
-
-               # Compute 95% line.
-               "VDEF:bits_95p=bits,95,PERCENT",
-
-               # Draw the received area.
-               "AREA:bits_rx#228B2277:%-15s" % _("Received"),
-               "VDEF:bits_rx_min=bits_rx,MINIMUM",
-               "VDEF:bits_rx_max=bits_rx,MAXIMUM",
-               "VDEF:bits_rx_avg=bits_rx,AVERAGE",
-               "GPRINT:bits_rx_max:%12s\: " % _("Maximum") + _("%8.2lf %sbps"),
-               "GPRINT:bits_rx_min:%12s\: " % _("Minimum") + _("%8.2lf %sbps"),
-               "GPRINT:bits_rx_avg:%12s\: " % _("Average") + _("%8.2lf %sbps") + "\\n",
-               "LINE1:bits_rx#228B22",
-
-               # Draw the transmitted area.
-               "AREA:bits_tx_inv#B2222277:%-15s" % _("Transmitted"),
-               "VDEF:bits_tx_min=bits_tx,MINIMUM",
-               "VDEF:bits_tx_max=bits_tx,MAXIMUM",
-               "VDEF:bits_tx_avg=bits_tx,AVERAGE",
-               "GPRINT:bits_tx_max:%12s\: " % _("Maximum") + _("%8.2lf %sbps"),
-               "GPRINT:bits_tx_min:%12s\: " % _("Minimum") + _("%8.2lf %sbps"),
-               "GPRINT:bits_tx_avg:%12s\: " % _("Average") + _("%8.2lf %sbps") + "\\n",
-               "LINE1:bits_tx_inv#B22222",
-
-               # Draw the 95% line.
-               "LINE1:bits_95p#000000:%-15s" % _("95th percentile"),
-               "GPRINT:bits_95p:%s" % _("%8.2lf %sbps") + "\\n",
-       ]
+COLOUR_RX = "B22222"
+COLOUR_RX_AREA = "%sAA" % COLOUR_RX
+COLOUR_TX = "228B22"
+COLOUR_TX_AREA = "%sAA" % COLOUR_TX
 
 
-       rrd_graph_args = [
-               "--title", _("Bandwidth usage on %(interface)s"),
-               "--vertical-label", _("Bit/s"),
-       ]
+class GraphTemplateInterfaceBits(base.GraphTemplate):
+       name = "interface-bits"
+
+       @property
+       def rrd_graph(self):
+               return [
+                       "DEF:bytes_rx=%(file)s:bytes_rx:AVERAGE",
+                       "DEF:bytes_tx=%(file)s:bytes_tx:AVERAGE",
+
+                       # Convert everything into bits.
+                       "CDEF:bits_rx=bytes_rx,8,*",
+                       "CDEF:bits_tx=bytes_tx,8,*",
+
+                       # Compute 95% lines.
+                       "VDEF:bits_rx_95p=bits_rx,95,PERCENT",
+                       "VDEF:bits_tx_95p=bits_tx,95,PERCENT",
+
+                       # Draw the received area.
+                       "AREA:bits_rx#%s:%-15s" % (COLOUR_RX_AREA, _("Received")),
+                       "VDEF:bits_rx_min=bits_rx,MINIMUM",
+                       "VDEF:bits_rx_max=bits_rx,MAXIMUM",
+                       "VDEF:bits_rx_avg=bits_rx,AVERAGE",
+                       "GPRINT:bits_rx_max:%12s\: " % _("Maximum") + _("%8.2lf %sbps"),
+                       "GPRINT:bits_rx_min:%12s\: " % _("Minimum") + _("%8.2lf %sbps"),
+                       "GPRINT:bits_rx_avg:%12s\: " % _("Average") + _("%8.2lf %sbps") + "\\n",
+
+                       # Draw the transmitted area.
+                       "AREA:bits_tx#%s:%-15s" % (COLOUR_TX_AREA, _("Transmitted")),
+                       "VDEF:bits_tx_min=bits_tx,MINIMUM",
+                       "VDEF:bits_tx_max=bits_tx,MAXIMUM",
+                       "VDEF:bits_tx_avg=bits_tx,AVERAGE",
+                       "GPRINT:bits_tx_max:%12s\: " % _("Maximum") + _("%8.2lf %sbps"),
+                       "GPRINT:bits_tx_min:%12s\: " % _("Minimum") + _("%8.2lf %sbps"),
+                       "GPRINT:bits_tx_avg:%12s\: " % _("Average") + _("%8.2lf %sbps") + "\\n",
+
+                       # Draw outlines.
+                       "LINE1:bits_rx#%s" % COLOUR_RX,
+                       "LINE1:bits_tx#%s" % COLOUR_TX,
+
+                       # Draw the 95% lines.
+                       "COMMENT:--- %s ---\\n" % _("95th percentile"),
+                       "LINE2:bits_rx_95p#%s:%-15s" % (COLOUR_RX, _("Received")),
+                       "GPRINT:bits_rx_95p:%s" % _("%8.2lf %sbps") + "\\n",
+                       "LINE2:bits_tx_95p#%s:%-15s" % (COLOUR_TX, _("Transmitted")),
+                       "GPRINT:bits_tx_95p:%s" % _("%8.2lf %sbps") + "\\n",
+               ]
+
+       @property
+       def rrd_graph_args(self):
+               return [
+                       "--title", _("Bandwidth usage on %(interface)s"),
+                       "--vertical-label", _("Bit/s"),
+               ]
 
 
 class GraphTemplateInterfacePackets(base.GraphTemplate):
        name = "interface-packets"
 
 
 
 class GraphTemplateInterfacePackets(base.GraphTemplate):
        name = "interface-packets"
 
-       rrd_graph = [
-               "DEF:packets_rx=%(file)s:packets_rx:AVERAGE",
-               "DEF:packets_tx=%(file)s:packets_tx:AVERAGE",
-
-               # Invert the transmitted packets to create upside down graph.
-               "CDEF:packets_tx_inv=packets_tx,-1,*",
-
-               # Draw the received area.
-               "AREA:packets_rx#228B2277:%-15s" % _("Received"),
-               "VDEF:packets_rx_min=packets_rx,MINIMUM",
-               "VDEF:packets_rx_max=packets_rx,MAXIMUM",
-               "VDEF:packets_rx_avg=packets_rx,AVERAGE",
-               "GPRINT:packets_rx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
-               "GPRINT:packets_rx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
-               "GPRINT:packets_rx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
-               "LINE1:packets_rx#228B22",
-
-               # Draw the transmitted area.
-               "AREA:packets_tx_inv#B2222277:%-15s" % _("Transmitted"),
-               "VDEF:packets_tx_min=packets_tx,MINIMUM",
-               "VDEF:packets_tx_max=packets_tx,MAXIMUM",
-               "VDEF:packets_tx_avg=packets_tx,AVERAGE",
-               "GPRINT:packets_tx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
-               "GPRINT:packets_tx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
-               "GPRINT:packets_tx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
-               "LINE1:packets_tx_inv#B22222",
-       ]
+       @property
+       def rrd_graph(self):
+               return [
+                       "DEF:packets_rx=%(file)s:packets_rx:AVERAGE",
+                       "DEF:packets_tx=%(file)s:packets_tx:AVERAGE",
+
+                       # Draw the received area.
+                       "AREA:packets_rx#%s:%-15s" % (COLOUR_RX_AREA, _("Received")),
+                       "VDEF:packets_rx_min=packets_rx,MINIMUM",
+                       "VDEF:packets_rx_max=packets_rx,MAXIMUM",
+                       "VDEF:packets_rx_avg=packets_rx,AVERAGE",
+                       "GPRINT:packets_rx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
+                       "GPRINT:packets_rx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
+                       "GPRINT:packets_rx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
+
+                       # Draw the transmitted area.
+                       "AREA:packets_tx#%s:%-15s" % (COLOUR_TX_AREA, _("Transmitted")),
+                       "VDEF:packets_tx_min=packets_tx,MINIMUM",
+                       "VDEF:packets_tx_max=packets_tx,MAXIMUM",
+                       "VDEF:packets_tx_avg=packets_tx,AVERAGE",
+                       "GPRINT:packets_tx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
+                       "GPRINT:packets_tx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
+                       "GPRINT:packets_tx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
+
+                       # Draw outlines of the areas on top.
+                       "LINE1:packets_rx#%s" % COLOUR_RX,
+                       "LINE1:packets_tx#%s" % COLOUR_TX,
+               ]
 
 
-       rrd_graph_args = [
-               "--title", _("Transferred packets on %(interface)s"),
-               "--vertical-label", _("Packets/s"),
-       ]
+       @property
+       def rrd_graph_args(self):
+               return [
+                       "--title", _("Transferred packets on %(interface)s"),
+                       "--vertical-label", _("Packets/s"),
+               ]
 
 
 class GraphTemplateInterfaceErrors(base.GraphTemplate):
        name = "interface-errors"
 
 
 
 class GraphTemplateInterfaceErrors(base.GraphTemplate):
        name = "interface-errors"
 
-       rrd_graph = [
-               "DEF:errors_rx=%(file)s:errors_rx:AVERAGE",
-               "DEF:errors_tx=%(file)s:errors_tx:AVERAGE",
-               "DEF:dropped_rx=%(file)s:dropped_rx:AVERAGE",
-               "DEF:dropped_tx=%(file)s:dropped_tx:AVERAGE",
-               "DEF:collisions=%(file)s:collisions:AVERAGE",
-
-               # Invert the transmitted packets to create upside down graph.
-               "CDEF:errors_tx_inv=errors_tx,-1,*",
-               "CDEF:dropped_tx_inv=dropped_tx,-1,*",
-
-               # Draw the receive errors.
-               "AREA:errors_rx#228B2277:%-15s" % _("Receive errors"),
-               "VDEF:errors_rx_min=errors_rx,MINIMUM",
-               "VDEF:errors_rx_max=errors_rx,MAXIMUM",
-               "VDEF:errors_rx_avg=errors_rx,AVERAGE",
-               "GPRINT:errors_rx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
-               "GPRINT:errors_rx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
-               "GPRINT:errors_rx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
-               "LINE1:errors_rx#228B22",
-
-               # Draw the transmit errors.
-               "AREA:errors_tx_inv#B2222277:%-15s" % _("Transmit errors"),
-               "VDEF:errors_tx_min=errors_tx,MINIMUM",
-               "VDEF:errors_tx_max=errors_tx,MAXIMUM",
-               "VDEF:errors_tx_avg=errors_tx,AVERAGE",
-               "GPRINT:errors_tx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
-               "GPRINT:errors_tx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
-               "GPRINT:errors_tx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
-               "LINE1:errors_tx_inv#B22222",
-
-               # Draw the receive drops.
-               "LINE2:dropped_rx#228B22:%-15s" % _("Receive drops"),
-               "VDEF:dropped_rx_min=dropped_rx,MINIMUM",
-               "VDEF:dropped_rx_max=dropped_rx,MAXIMUM",
-               "VDEF:dropped_rx_avg=dropped_rx,AVERAGE",
-               "GPRINT:dropped_rx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
-               "GPRINT:dropped_rx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
-               "GPRINT:dropped_rx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
-               "LINE1:dropped_rx#228B22",
-
-               # Draw the transmit drops.
-               "LINE2:dropped_tx#B22222:%-15s" % _("Transmit drops"),
-               "VDEF:dropped_tx_min=dropped_tx,MINIMUM",
-               "VDEF:dropped_tx_max=dropped_tx,MAXIMUM",
-               "VDEF:dropped_tx_avg=dropped_tx,AVERAGE",
-               "GPRINT:dropped_tx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
-               "GPRINT:dropped_tx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
-               "GPRINT:dropped_tx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
-               "LINE1:dropped_tx#B22222",
-
-               # Draw the collisions as a line.
-               "LINE3:collisions#8B0000:%-15s" % _("Collisions") + "\\n",
-       ]
+       @property
+       def rrd_graph(self):
+               return [
+                       "DEF:errors_rx=%(file)s:errors_rx:AVERAGE",
+                       "DEF:errors_tx=%(file)s:errors_tx:AVERAGE",
+                       "DEF:dropped_rx=%(file)s:dropped_rx:AVERAGE",
+                       "DEF:dropped_tx=%(file)s:dropped_tx:AVERAGE",
+                       "DEF:collisions=%(file)s:collisions:AVERAGE",
+
+                       # Invert the transmitted packets to create upside down graph.
+                       "CDEF:errors_tx_inv=errors_tx,-1,*",
+                       "CDEF:dropped_tx_inv=dropped_tx,-1,*",
+
+                       # Draw the receive errors.
+                       "AREA:errors_rx#228B2277:%-15s" % _("Receive errors"),
+                       "VDEF:errors_rx_min=errors_rx,MINIMUM",
+                       "VDEF:errors_rx_max=errors_rx,MAXIMUM",
+                       "VDEF:errors_rx_avg=errors_rx,AVERAGE",
+                       "GPRINT:errors_rx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
+                       "GPRINT:errors_rx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
+                       "GPRINT:errors_rx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
+                       "LINE1:errors_rx#228B22",
+
+                       # Draw the transmit errors.
+                       "AREA:errors_tx_inv#B2222277:%-15s" % _("Transmit errors"),
+                       "VDEF:errors_tx_min=errors_tx,MINIMUM",
+                       "VDEF:errors_tx_max=errors_tx,MAXIMUM",
+                       "VDEF:errors_tx_avg=errors_tx,AVERAGE",
+                       "GPRINT:errors_tx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
+                       "GPRINT:errors_tx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
+                       "GPRINT:errors_tx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
+                       "LINE1:errors_tx_inv#B22222",
+
+                       # Draw the receive drops.
+                       "LINE2:dropped_rx#228B22:%-15s" % _("Receive drops"),
+                       "VDEF:dropped_rx_min=dropped_rx,MINIMUM",
+                       "VDEF:dropped_rx_max=dropped_rx,MAXIMUM",
+                       "VDEF:dropped_rx_avg=dropped_rx,AVERAGE",
+                       "GPRINT:dropped_rx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
+                       "GPRINT:dropped_rx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
+                       "GPRINT:dropped_rx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
+                       "LINE1:dropped_rx#228B22",
+
+                       # Draw the transmit drops.
+                       "LINE2:dropped_tx#B22222:%-15s" % _("Transmit drops"),
+                       "VDEF:dropped_tx_min=dropped_tx,MINIMUM",
+                       "VDEF:dropped_tx_max=dropped_tx,MAXIMUM",
+                       "VDEF:dropped_tx_avg=dropped_tx,AVERAGE",
+                       "GPRINT:dropped_tx_max:%12s\: " % _("Maximum") + _("%8.0lf %spps"),
+                       "GPRINT:dropped_tx_min:%12s\: " % _("Minimum") + _("%8.0lf %spps"),
+                       "GPRINT:dropped_tx_avg:%12s\: " % _("Average") + _("%8.2lf %spps") + "\\n",
+                       "LINE1:dropped_tx#B22222",
+
+                       # Draw the collisions as a line.
+                       "LINE3:collisions#8B0000:%-15s" % _("Collisions") + "\\n",
+               ]
 
 
-       rrd_graph_args = [
-               "--title", _("Errors/dropped packets on %(interface)s"),
-               "--vertical-label", _("Packets/s"),
-       ]
+       @property
+       def rrd_graph_args(self):
+               return [
+                       "--title", _("Errors/dropped packets on %(interface)s"),
+                       "--vertical-label", _("Packets/s"),
+               ]
 
 
 class DataSourceInterface(base.DataSource):
 
 
 class DataSourceInterface(base.DataSource):
@@ -186,7 +202,7 @@ class DataSourceInterface(base.DataSource):
        description = "Interface Statistics Data Source"
 
        templates = [
        description = "Interface Statistics Data Source"
 
        templates = [
-               GraphTemplateInterfaceBytes,
+               GraphTemplateInterfaceBits,
                GraphTemplateInterfacePackets,
                GraphTemplateInterfaceErrors,
        ]
                GraphTemplateInterfacePackets,
                GraphTemplateInterfaceErrors,
        ]
@@ -211,6 +227,10 @@ class DataSourceInterface(base.DataSource):
 
                instances = []
                for interface in os.listdir(SYS_CLASS_NET):
 
                instances = []
                for interface in os.listdir(SYS_CLASS_NET):
+                       # Skip some unwanted interfaces.
+                       if interface == "lo" or interface.startswith("mon."):
+                               continue
+
                        path = os.path.join(SYS_CLASS_NET, interface)
                        if not os.path.isdir(path):
                                continue
                        path = os.path.join(SYS_CLASS_NET, interface)
                        if not os.path.isdir(path):
                                continue
@@ -228,6 +248,14 @@ class DataSourceInterface(base.DataSource):
                return "-".join((self.name, self.interface))
 
        def read(self):
                return "-".join((self.name, self.interface))
 
        def read(self):
+               interface_path = os.path.join(SYS_CLASS_NET, self.interface)
+
+               # Check if the interface exists.
+               if not os.path.exists(interface_path):
+                       self.log.debug(_("Interface %s does not exists. Cannot collect.") \
+                               % self.interface)
+                       return
+
                files = (
                        "rx_bytes", "tx_bytes",
                        "collisions",
                files = (
                        "rx_bytes", "tx_bytes",
                        "collisions",
@@ -236,18 +264,25 @@ class DataSourceInterface(base.DataSource):
                        "multicast",
                        "rx_packets", "tx_packets",
                )
                        "multicast",
                        "rx_packets", "tx_packets",
                )
-               ret = ["%s" % self.now,]
+               ret = []
 
                for file in files:
 
                for file in files:
-                       path = os.path.join(SYS_CLASS_NET, self.interface, "statistics", file)
+                       path = os.path.join(interface_path, "statistics", file)
 
                        # Open file and read it's content.
 
                        # Open file and read it's content.
-                       f = open(path)
-
-                       line = f.readline()
-                       line = line.strip()
-                       ret.append(line)
-
-                       f.close()
-
-               self.data.append(":".join(ret))
+                       f = None
+                       try:
+                               f = open(path)
+
+                               line = f.readline()
+                               line = line.strip()
+                               ret.append(line)
+                       except:
+                               ret.append("0")
+                               raise
+
+                       finally:
+                               if f:
+                                       f.close()
+
+               return ":".join(ret)
index 103627f6891a129e1e7e41a6fa4004620c3ceec2..6e4a54d2c0b4298c5ff812b11ab4a747e5d78b24 100644 (file)
@@ -86,8 +86,4 @@ class DataSourceLoadAvg(base.DataSource):
                return cls(collecty, **kwargs)
 
        def read(self):
                return cls(collecty, **kwargs)
 
        def read(self):
-               data = "%s" % self.now
-               for load in os.getloadavg():
-                       data += ":%s" % load
-
-               self.data.append(data)
+               return ":".join(["%.10f" % l for l in os.getloadavg()])
index b9fb1979778aff425a79e7c4a1df9ebff1022606..ae90968a783564b573919886d10f9752daee68eb 100644 (file)
@@ -110,8 +110,6 @@ class DataSourceMemory(base.DataSource):
                f = None
 
                try:
                f = None
 
                try:
-                       ret = "%s" % self.now
-
                        f = open("/proc/meminfo")
                        for line in f.readlines():
                                if line.startswith("MemTotal:"):
                        f = open("/proc/meminfo")
                        for line in f.readlines():
                                if line.startswith("MemTotal:"):
@@ -127,17 +125,19 @@ class DataSourceMemory(base.DataSource):
                                elif line.startswith("SwapFree:"):
                                        swapf = float(line.split()[1])
 
                                elif line.startswith("SwapFree:"):
                                        swapf = float(line.split()[1])
 
-                       ret += ":%s" % ((total - (free + buffered + cached)) * 100 / total)
-                       ret += ":%s" % (cached * 100 / total)
-                       ret += ":%s" % (buffered * 100 / total)
-                       ret += ":%s" % (free * 100 / total)
+                       ret = [
+                               "%s" % ((total - (free + buffered + cached)) * 100 / total),
+                               "%s" % (cached * 100 / total),
+                               "%s" % (buffered * 100 / total),
+                               "%s" % (free * 100 / total),
+                       ]
 
                        if swapt:
 
                        if swapt:
-                               ret += ":%s" % ((swapt - swapf) * 100 / swapt)
+                               ret.append("%s" % ((swapt - swapf) * 100 / swapt))
                        else:
                        else:
-                               ret += ":0"
+                               ret.append("0")
 
 
-                       self.data.append(ret)
+                       return ":".join(ret)
                finally:
                        if f:
                                f.close()
                finally:
                        if f:
                                f.close()