]>
git.ipfire.org Git - collecty.git/blob - src/collecty/client.py
2 ###############################################################################
4 # collecty - A system statistics collection daemon for IPFire #
5 # Copyright (C) 2012 IPFire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
26 from constants
import *
30 log
= logging
.getLogger("collectly.client")
32 class CollectyClient(object):
34 self
.bus
= dbus
.SystemBus()
36 self
.proxy
= self
.bus
.get_object(BUS_DOMAIN
, "/GraphGenerator")
38 def list_templates(self
):
39 templates
= self
.proxy
.ListTemplates()
41 return ["%s" % t
for t
in templates
]
43 def list_templates_cli(self
, ns
):
44 templates
= self
.list_templates()
46 for t
in sorted(templates
):
49 def generate_graph(self
, template_name
, **kwargs
):
50 byte_array
= self
.proxy
.GenerateGraph(template_name
, kwargs
,
53 # Convert the byte array into a byte string again
55 return "".join((chr(b
) for b
in byte_array
))
57 def generate_graph_cli(self
, ns
):
59 "object_id" : ns
.object,
62 if ns
.height
or ns
.width
:
64 "height" : ns
.height
or 0,
65 "width" : ns
.width
or 0,
69 kwargs
["interval"] = ns
.interval
71 # Generate the graph image
72 graph
= self
.generate_graph(ns
.template
, **kwargs
)
75 with
open(ns
.filename
, "wb") as f
:
78 def parse_cli(self
, args
):
79 parser
= argparse
.ArgumentParser(prog
="collecty-client")
80 subparsers
= parser
.add_subparsers(help="sub-command help")
83 parser_generate_graph
= subparsers
.add_parser("generate-graph",
84 help=_("Generate a graph image"))
85 parser_generate_graph
.set_defaults(func
=self
.generate_graph_cli
)
86 parser_generate_graph
.add_argument("--filename",
87 help=_("filename"), required
=True)
88 parser_generate_graph
.add_argument("--interval", help=_("interval"))
89 parser_generate_graph
.add_argument("--object",
90 help=_("Object identifier"), default
="default")
91 parser_generate_graph
.add_argument("--template",
92 help=_("The graph template identifier"), required
=True)
95 parser_generate_graph
.add_argument("--height", type=int, default
=0,
96 help=_("Height of the generated image"))
97 parser_generate_graph
.add_argument("--width", type=int, default
=0,
98 help=_("Width of the generated image"))
101 parser_list_templates
= subparsers
.add_parser("list-templates",
102 help=_("Lists all graph templates"))
103 parser_list_templates
.set_defaults(func
=self
.list_templates_cli
)
105 return parser
.parse_args(args
)
107 def run_cli(self
, args
=None):
108 args
= self
.parse_cli(args
or sys
.argv
[1:])
110 return args
.func(args
)