From f181246a44db1e5e80a6181bd94ca70502878cc3 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 19 May 2015 10:11:51 +0000 Subject: [PATCH 1/1] graph templates: Make some atttibutes easier to set 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 | 28 ++++++++++++++++++++++++++ src/collecty/plugins/cpu.py | 13 +++++++----- src/collecty/plugins/entropy.py | 13 +++++++----- src/collecty/plugins/interface.py | 33 +++++++++++++++++-------------- src/collecty/plugins/latency.py | 13 ++++++------ src/collecty/plugins/loadavg.py | 13 +++++++----- src/collecty/plugins/memory.py | 17 ++++++++-------- 7 files changed, 86 insertions(+), 44 deletions(-) diff --git a/src/collecty/plugins/base.py b/src/collecty/plugins/base.py index 1a03105..6a88ae8 100644 --- a/src/collecty/plugins/base.py +++ b/src/collecty/plugins/base.py @@ -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") diff --git a/src/collecty/plugins/cpu.py b/src/collecty/plugins/cpu.py index c2f0183..292bf0c 100644 --- a/src/collecty/plugins/cpu.py +++ b/src/collecty/plugins/cpu.py @@ -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): diff --git a/src/collecty/plugins/entropy.py b/src/collecty/plugins/entropy.py index 4296c77..e6e920d 100644 --- a/src/collecty/plugins/entropy.py +++ b/src/collecty/plugins/entropy.py @@ -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): diff --git a/src/collecty/plugins/interface.py b/src/collecty/plugins/interface.py index 4ab5f01..3ad6e8b 100644 --- a/src/collecty/plugins/interface.py +++ b/src/collecty/plugins/interface.py @@ -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): diff --git a/src/collecty/plugins/latency.py b/src/collecty/plugins/latency.py index 589afa8..a6db8d0 100644 --- a/src/collecty/plugins/latency.py +++ b/src/collecty/plugins/latency.py @@ -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): diff --git a/src/collecty/plugins/loadavg.py b/src/collecty/plugins/loadavg.py index b8cf07a..c7e5e14 100644 --- a/src/collecty/plugins/loadavg.py +++ b/src/collecty/plugins/loadavg.py @@ -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): diff --git a/src/collecty/plugins/memory.py b/src/collecty/plugins/memory.py index d640077..7fcf115 100644 --- a/src/collecty/plugins/memory.py +++ b/src/collecty/plugins/memory.py @@ -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): -- 2.39.2