try:
result = o.collect()
- if isinstance(result, tuple) or isinstance(result, list):
- result = ":".join(("%s" % e for e in result))
+ result = self._format_result(result)
except:
self.log.warning(_("Unhandled exception in %s.collect()") % o, exc_info=True)
continue
if delay >= 60:
self.log.warning(_("A worker thread was stalled for %.4fs") % delay)
+ @staticmethod
+ def _format_result(result):
+ if not isinstance(result, tuple) and not isinstance(result, list):
+ return result
+
+ # Replace all Nones by NaN
+ s = []
+
+ for e in result:
+ if e is None:
+ e = "NaN"
+
+ # Format as string
+ e = "%s" % e
+
+ s.append(e)
+
+ return ":".join(s)
+
def get_object(self, id):
for object in self.objects:
if not object.id == id:
rrd_schema = None
# RRA properties.
- rra_types = ["AVERAGE", "MIN", "MAX"]
- rra_timespans = [3600, 86400, 604800, 2678400, 31622400]
- rra_rows = 2880
+ rra_types = ("AVERAGE", "MIN", "MAX")
+ rra_timespans = (
+ ("1m", "10d"),
+ ("1h", "18M"),
+ ("1d", "5y"),
+ )
def __init__(self, plugin, *args, **kwargs):
self.plugin = plugin
xff = 0.1
- cdp_length = 0
- for rra_timespan in self.rra_timespans:
- if (rra_timespan / self.stepsize) < self.rra_rows:
- rra_timespan = self.stepsize * self.rra_rows
-
- if cdp_length == 0:
- cdp_length = 1
- else:
- cdp_length = rra_timespan // (self.rra_rows * self.stepsize)
-
- cdp_number = math.ceil(rra_timespan / (cdp_length * self.stepsize))
-
- for rra_type in self.rra_types:
- schema.append("RRA:%s:%.10f:%d:%d" % \
- (rra_type, xff, cdp_length, cdp_number))
+ for steps, rows in self.rra_timespans:
+ for type in self.rra_types:
+ schema.append("RRA:%s:%s:%s:%s" % (type, xff, steps, rows))
return schema
None : "-3h",
"hour" : "-1h",
"day" : "-25h",
+ "month": "-30d",
"week" : "-360h",
"year" : "-365d",
}
if self.upper_limit is not None:
args += ["--upper-limit", self.upper_limit]
- # Add interval
- args.append("--start")
-
try:
- args.append(self.intervals[interval])
+ interval = self.intervals[interval]
except KeyError:
- args.append(str(interval))
+ interval = "end-%s" % interval
+
+ # Add interval
+ args += ["--start", interval]
return args
self.log.debug(" %s" % args[-1])
- return self.write_graph(*args)
-
- def write_graph(self, *args):
- # Convert all arguments to string
+ # Convert arguments to string
args = [str(e) for e in args]
- with tempfile.NamedTemporaryFile() as f:
- rrdtool.graph(f.name, *args)
-
- # Get back to the beginning of the file
- f.seek(0)
+ graph = rrdtool.graphv("-", *args)
- # Return all the content
- return f.read()
+ return graph.get("image")