Forgot this one into the previous commit :p

see #333
This commit is contained in:
Antoine Nguyen
2012-11-12 23:13:32 +01:00
parent c65ce99193
commit 81ef3b3683
+14 -14
View File
@@ -31,23 +31,23 @@ class Grapher(object):
self.rrd_rootdir = parameters.get_admin("RRD_ROOTDIR")
self.img_rootdir = parameters.get_admin("IMG_ROOTDIR")
def process(self, target, suffix, start, end, tpl):
def process(self, target, suffix, start, end, graph_tpl):
import rrdtool
rrdfile = "%s/%s.rrd" % (self.rrd_rootdir, target)
if not os.path.exists(rrdfile):
return
ext = "png"
path = "%s/%s_%s_%s_%s.%s" % (self.img_rootdir, tpl['name'],
target, tpl['cf'], suffix, ext)
path = "%s/%s_%s_%s_%s.%s" % (self.img_rootdir, graph_tpl.display_name,
target, graph_tpl.cf, suffix, ext)
start = str(start)
end = str(end)
defs = []
lines = []
defs.append('COMMENT: %s %s %s %s\\c' % ("From", start, "to", end))
defs.append('COMMENT:\\s')
for v, d in tpl["vars"].iteritems():
defs += [str('DEF:%s=%s:%s:%s' % (v, rrdfile, v, tpl['cf'])),
for v, d in graph_tpl.vars.iteritems():
defs += [str('DEF:%s=%s:%s:%s' % (v, rrdfile, v, graph_tpl.cf)),
str('CDEF:%spm=%s,60,*' % (v, v)),
str('VDEF:%s_total=%s,TOTAL' % (v, v))]
type = d.has_key("type") and d["type"] or "LINE"
@@ -58,25 +58,25 @@ class Grapher(object):
params = defs + lines
rrdtool.graph(str(path),
"--imgformat", "PNG",
"--width", tpl["width"],
"--height", tpl["height"],
"--width", str(graph_tpl.width),
"--height", str(graph_tpl.height),
"--start", start,
"--end", end,
"--vertical-label", tpl["vertlabel"].encode("utf-8"),
"--vertical-label", graph_tpl.vertlabel.encode("utf-8"),
"--lower-limit", "0",
"--slope-mode",
"--units-exponent", "0",
"--title", tpl["title"].encode("utf-8"),
"--title", graph_tpl.title.encode("utf-8"),
*params)
if not os.path.exists(path):
print "[graph] Impossible to create %s graph" %path
def make_defaults(self, target, tpl):
def make_defaults(self, target, graph_tpl):
end = "%d" % int(time.mktime(time.localtime()))
self.process(target, "day", "-1day", end, tpl)
self.process(target, "week", "-1week", end, tpl)
self.process(target, "month", "-1month", end, tpl)
self.process(target, "year", "-1year", end, tpl)
self.process(target, "day", "-1day", end, graph_tpl)
self.process(target, "week", "-1week", end, graph_tpl)
self.process(target, "month", "-1month", end, graph_tpl)
self.process(target, "year", "-1year", end, graph_tpl)