Allow getting the standard deviation of the plotted values
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 14 Dec 2015 22:50:19 +0000 (23:50 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 14 Dec 2015 22:50:19 +0000 (23:50 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/collecty/constants.py
src/collecty/plugins/base.py
src/collecty/util.py

index bae6ed4..082203e 100644 (file)
@@ -55,6 +55,15 @@ GRAPH_DEFAULT_ARGUMENTS = (
        "--watermark", _("Created by collecty"),
 )
 
+INTERVALS = {
+       None   : "-3h",
+       "hour" : "-1h",
+       "day"  : "-25h",
+       "month": "-30d",
+       "week" : "-360h",
+       "year" : "-365d",
+}
+
 GRAPH_DEFAULT_WIDTH = 768
 GRAPH_DEFAULT_HEIGHT = 480
 
index dd7f0d9..c1666b6 100644 (file)
@@ -31,6 +31,7 @@ import time
 import unicodedata
 
 from .. import locales
+from .. import util
 from ..constants import *
 from ..i18n import _
 
@@ -465,6 +466,21 @@ class Object(object):
 
                return defs
 
+       def get_stddev(self, interval=None):
+               args = self.make_rrd_defs()
+
+               # Add the correct interval
+               args += ["--start", util.make_interval(interval)]
+
+               for name in self.rrd_schema_names:
+                       args += [
+                               "VDEF:%s_stddev=%s,STDEV" % (name, name),
+                               "PRINT:%s_stddev:%%lf" % name,
+                       ]
+
+               x, y, vals = rrdtool.graph("/dev/null", *args)
+               return dict(zip(self.rrd_schema_names, vals))
+
        def execute(self):
                if self.collected:
                        raise RuntimeError("This object has already collected its data")
@@ -506,15 +522,6 @@ class GraphTemplate(object):
        # Extra arguments passed to rrdgraph.
        rrd_graph_args = []
 
-       intervals = {
-               None   : "-3h",
-               "hour" : "-1h",
-               "day"  : "-25h",
-               "month": "-30d",
-               "week" : "-360h",
-               "year" : "-365d",
-       }
-
        # Default dimensions for this graph
        height = GRAPH_DEFAULT_HEIGHT
        width  = GRAPH_DEFAULT_WIDTH
@@ -583,13 +590,8 @@ class GraphTemplate(object):
                        if self.upper_limit is not None:
                                args += ["--upper-limit", self.upper_limit]
 
-               try:
-                       interval = self.intervals[interval]
-               except KeyError:
-                       interval = "end-%s" % interval
-
                # Add interval
-               args += ["--start", interval]
+               args += ["--start", util.make_interval(interval)]
 
                return args
 
index fdde126..72fc0c1 100644 (file)
@@ -72,6 +72,12 @@ def get_network_interfaces():
 
                yield interface
 
+def make_interval(interval):
+       try:
+               return INTERVALS[interval]
+       except KeyError:
+               return "end-%s" % interval
+
 class ProcNetSnmpParser(object):
        """
                This class parses /proc/net/snmp{,6} and allows