From 4d9ed86ed569cd0eaf4fe4211b84b41c241dd5a9 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 14 Dec 2015 23:50:19 +0100 Subject: [PATCH] Allow getting the standard deviation of the plotted values Signed-off-by: Michael Tremer --- src/collecty/constants.py | 9 +++++++++ src/collecty/plugins/base.py | 32 +++++++++++++++++--------------- src/collecty/util.py | 6 ++++++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/collecty/constants.py b/src/collecty/constants.py index bae6ed4..082203e 100644 --- a/src/collecty/constants.py +++ b/src/collecty/constants.py @@ -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 diff --git a/src/collecty/plugins/base.py b/src/collecty/plugins/base.py index dd7f0d9..c1666b6 100644 --- a/src/collecty/plugins/base.py +++ b/src/collecty/plugins/base.py @@ -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 diff --git a/src/collecty/util.py b/src/collecty/util.py index fdde126..72fc0c1 100644 --- a/src/collecty/util.py +++ b/src/collecty/util.py @@ -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 -- 2.39.2