]> git.ipfire.org Git - oddments/collecty.git/commitdiff
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 bae6ed42bac5610c516e7ccc8b9c09391fcfbc7c..082203e38bdc84c9311da3c15391246a8f0a75b1 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 dd7f0d99156695c437c2035e18ab0aefe7b80368..c1666b6b3474809d9b7ef90d78e95e0257de4f83 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 fdde1262e6f9aebdec3ca640da66f05f7979a25b..72fc0c1d78227e4c92d29137a15c041cf0953b44 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