self.collecty = collecty
- @dbus.service.method(BUS_DOMAIN, in_signature="sa{sv}", out_signature="ay")
+ @dbus.service.method(BUS_DOMAIN, in_signature="sa{sv}", out_signature="a{sv}")
def GenerateGraph(self, template_name, kwargs):
"""
Returns a graph generated from the given template and object.
"""
graph = self.collecty.generate_graph(template_name, **kwargs)
- return dbus.ByteArray(graph or [])
+ # Convert the graph back to normal Python format
+ if graph:
+ graph["image"] = dbus.ByteArray(graph["image"] or [])
+
+ return graph
+
+ @dbus.service.method(BUS_DOMAIN, in_signature="", out_signature="a{sv}")
+ def GraphInfo(self, template_name, kwargs):
+ """
+ Returns a dictionary with information about the graph.
+ """
+ return self.collecty.graph_info(template_name, **kwargs)
@dbus.service.method(BUS_DOMAIN, in_signature="", out_signature="as")
def ListTemplates(self):
for t in sorted(templates):
print(t)
+ def graph_info(self, template_name, **kwargs):
+ graph_info = self.proxy.GraphInfo(template_name, kwargs,
+ signature="sa{sv}")
+
+ return dict(graph_info)
+
def generate_graph(self, template_name, **kwargs):
- byte_array = self.proxy.GenerateGraph(template_name, kwargs,
+ graph = self.proxy.GenerateGraph(template_name, kwargs,
signature="sa{sv}")
# Convert the byte array into a byte string again
- if byte_array:
- return bytes(byte_array)
+ if graph:
+ graph["image"] = bytes(graph["image"])
+
+ return graph
def generate_graph_cli(self, ns):
kwargs = {
# Generate the graph image
graph = self.generate_graph(ns.template, **kwargs)
+ # Add some useful information
+ info = self.graph_info(ns.template, **kwargs)
+ if info:
+ graph.update(info)
+
# Write file to disk
with open(ns.filename, "wb") as f:
- f.write(graph)
+ f.write(graph["image"])
+
+ print(_("Title : %(title)s (%(template)s - %(object_id)s)") % graph)
+ print(_("Image size : %(image_width)sx%(image_height)spx") % graph)
def version_cli(self, args):
daemon_version = self.proxy.Version()
return plugin.generate_graph(template_name, *args, **kwargs)
+ def graph_info(self, template_name, *args, **kwargs):
+ plugin = self.get_plugin_from_template(template_name)
+ if not plugin:
+ raise RuntimeError("Could not find template %s" % template_name)
+
+ return plugin.graph_info(template_name, *args, **kwargs)
+
def create_worker_threads(self, num=None):
"""
Creates a number of worker threads
return graph
+ def graph_info(self, template_name, object_id="default",
+ timezone=None, locale=None, **kwargs):
+ template = self.get_template(template_name, object_id=object_id,
+ timezone=timezone, locale=locale)
+ if not template:
+ raise RuntimeError("Could not find template %s" % template_name)
+
+ return template.graph_info()
+
class Object(object):
# The schema of the RRD database.
with Environment(self.timezone, self.locale.lang):
graph = rrdtool.graphv("-", *args)
- return graph.get("image")
+ return {
+ "image" : graph.get("image"),
+ "image_height" : graph.get("image_height"),
+ "image_width" : graph.get("image_width"),
+ }
+
+ def graph_info(self):
+ """
+ Returns a dictionary with useful information
+ about this graph.
+ """
+ return {
+ "title" : self.graph_title,
+ "object_id" : self.object_id or "",
+ "template" : self.name,
+ }