graph templates: Make some atttibutes easier to set
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 May 2015 10:11:51 +0000 (10:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 May 2015 10:11:51 +0000 (10:11 +0000)
Often used configuration settings like the title of the
graph and similar are now properties of the class and
can therefore be easier changed.

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

index 1a03105..6a88ae8 100644 (file)
@@ -378,6 +378,16 @@ class GraphTemplate(object):
        # A unique name to identify this graph template.
        name = None
 
+       # Headline of the graph image
+       graph_title = None
+
+       # Vertical label of the graph
+       graph_vertical_label = None
+
+       # Limits
+       lower_limit = None
+       upper_limit = None
+
        # Instructions how to create the graph.
        rrd_graph = None
 
@@ -424,6 +434,24 @@ class GraphTemplate(object):
 
                args += self.rrd_graph_args
 
+               # Graph title
+               if self.graph_title:
+                       args += ["--title", self.graph_title]
+
+               # Vertical label
+               if self.graph_vertical_label:
+                       args += ["--vertical-label", self.graph_vertical_label]
+
+               if self.lower_limit is not None or self.upper_limit is not None:
+                       # Force to honour the set limits
+                       args.append("--rigid")
+
+                       if self.lower_limit is not None:
+                               args += ["--lower-limit", self.lower_limit]
+
+                       if self.upper_limit is not None:
+                               args += ["--upper-limit", self.upper_limit]
+
                # Add interval
                args.append("--start")
 
index c2f0183..292bf0c 100644 (file)
@@ -94,12 +94,15 @@ class GraphTemplateProcessor(base.GraphTemplate):
                "GPRINT:idleavg:%12s\:" % _("Average") + " %6.2lf\\n",
        ]
 
-       rrd_graph_args = [
-               "--title", _("CPU usage"),
-               "--vertical-label", _("Jiffies"),
+       lower_limit = 0
 
-               "--lower-limit", "0", "--rigid",
-       ]
+       @property
+       def graph_title(self):
+               return _("CPU usage")
+
+       @property
+       def graph_vertical_label(self):
+               return _("Jiffies")
 
 
 class ProcessorObject(base.Object):
index 4296c77..e6e920d 100644 (file)
@@ -45,12 +45,15 @@ class GraphTemplateEntropy(base.GraphTemplate):
                "LINE3:entropytrend#000000",
        ]
 
-       rrd_graph_args = [
-               "--title", _("Available entropy"),
-               "--vertical-label", _("Bits"),
+       lower_limit = 0
 
-               "--lower-limit", "0", "--rigid",
-       ]
+       @property
+       def graph_title(self):
+               return _("Available entropy")
+
+       @property
+       def graph_vertical_label(self):
+               return _("Bit")
 
 
 class EntropyObject(base.Object):
index 4ab5f01..3ad6e8b 100644 (file)
@@ -82,11 +82,12 @@ class GraphTemplateInterfaceBits(base.GraphTemplate):
                ]
 
        @property
-       def rrd_graph_args(self):
-               return [
-                       "--title", _("Bandwidth usage on %(interface)s"),
-                       "--vertical-label", _("Bit/s"),
-               ]
+       def graph_title(self):
+               return _("Bandwidth usage on %(interface)s")
+
+       @property
+       def graph_vertical_label(self):
+               return _("Bit/s")
 
 
 class GraphTemplateInterfacePackets(base.GraphTemplate):
@@ -122,11 +123,12 @@ class GraphTemplateInterfacePackets(base.GraphTemplate):
                ]
 
        @property
-       def rrd_graph_args(self):
-               return [
-                       "--title", _("Transferred packets on %(interface)s"),
-                       "--vertical-label", _("Packets/s"),
-               ]
+       def graph_title(self):
+               return _("Transferred packets on %(interface)s")
+
+       @property
+       def graph_vertical_label(self):
+               return _("Packets/s")
 
 
 class GraphTemplateInterfaceErrors(base.GraphTemplate):
@@ -190,11 +192,12 @@ class GraphTemplateInterfaceErrors(base.GraphTemplate):
                ]
 
        @property
-       def rrd_graph_args(self):
-               return [
-                       "--title", _("Errors/dropped packets on %(interface)s"),
-                       "--vertical-label", _("Packets/s"),
-               ]
+       def graph_title(self):
+               return _("Errors/dropped packets on %(interface)s")
+
+       @property
+       def graph_vertical_label(self):
+               return _("Packets/s")
 
 
 class InterfaceObject(base.Object):
index 589afa8..a6db8d0 100644 (file)
@@ -32,6 +32,8 @@ PING_HOSTS = [
 class GraphTemplateLatency(base.GraphTemplate):
        name = "latency"
 
+       lower_limit = 0
+
        @property
        def rrd_graph(self):
                return [
@@ -73,13 +75,12 @@ class GraphTemplateLatency(base.GraphTemplate):
                ]
 
        @property
-       def rrd_graph_args(self):
-               return [
-                       "--title", _("Latency to %(host)s"),
-                       "--vertical-label", _("Milliseconds"),
+       def graph_title(self):
+               return _("Latency to %(host)s")
 
-                       "--lower-limit", "0", "--rigid",
-               ]
+       @property
+       def graph_vertical_label(self):
+               return _("Milliseconds")
 
 
 class LatencyObject(base.Object):
index b8cf07a..c7e5e14 100644 (file)
@@ -61,12 +61,15 @@ class GraphTemplateLoadAvg(base.GraphTemplate):
                "LINE:load1#dd0000",
        ]
 
-       rrd_graph_args = [
-               "--title", _("Load average"),
-               "--vertical-label", _("Load"),
+       lower_limit = 0
 
-               "--lower-limit", "0", "--rigid",
-       ]
+       @property
+       def graph_title(self):
+               return _("Load average")
+
+       @property
+       def graph_vertical_label(self):
+               return _("Load")
 
 
 class LoadAvgObject(base.Object):
index d640077..7fcf115 100644 (file)
@@ -28,6 +28,9 @@ from ..i18n import _
 class GraphTemplateMemory(base.GraphTemplate):
        name = "memory"
 
+       upper_limit = 100
+       lower_limit = 0
+
        rrd_graph = [
                "DEF:used=%(file)s:used:AVERAGE",
                "DEF:cached=%(file)s:cached:AVERAGE",
@@ -76,15 +79,13 @@ class GraphTemplateMemory(base.GraphTemplate):
                "GPRINT:swapavg:%12s\:" % _("Average") + " %6.2lf\\n",
        ]
 
-       rrd_graph_args = [
-               "--title", _("Memory Usage"),
-               "--vertical-label", _("Percent"),
+       @property
+       def graph_title(self):
+               return _("Memory Usage")
 
-               # Limit y axis.
-               "--upper-limit", "100",
-               "--lower-limit", "0",
-               "--rigid",
-       ]
+       @property
+       def graph_vertical_label(self):
+               return _("Percent")
 
 
 class MemoryObject(base.Object):