]> git.ipfire.org Git - collecty.git/blob - src/collecty/client.py
psi: Add graph template
[collecty.git] / src / collecty / client.py
1 #!/usr/bin/python3
2 ###############################################################################
3 # #
4 # collecty - A system statistics collection daemon for IPFire #
5 # Copyright (C) 2012 IPFire development team #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21
22 import argparse
23 import datetime
24 import dbus
25 import os
26 import platform
27 import sys
28
29 from . import bus
30 from .i18n import _
31
32 class Collecty(object):
33 def __init__(self):
34 self.bus = dbus.SystemBus()
35
36 self.proxy = self.bus.get_object(bus.DOMAIN, "/GraphGenerator")
37
38 def backup(self, filename):
39 """
40 Writes a backup of everything to file given filehandle
41 """
42 self.proxy.Backup(filename)
43
44 def last_update(self, template_name, **kwargs):
45 last_update = self.proxy.LastUpdate(template_name, kwargs)
46
47 if last_update:
48 last_update["timestamp"] = datetime.datetime.strptime(last_update["timestamp"], "%Y-%m-%dT%H:%M:%S")
49
50 return last_update
51
52 def list_templates(self):
53 templates = self.proxy.ListTemplates()
54
55 return ["%s" % t for t in templates]
56
57 def graph_info(self, template_name, **kwargs):
58 graph_info = self.proxy.GraphInfo(template_name, kwargs,
59 signature="sa{sv}")
60
61 return dict(graph_info)
62
63 def generate_graph(self, template_name, **kwargs):
64 graph = self.proxy.GenerateGraph(template_name, kwargs,
65 signature="sa{sv}")
66
67 # Convert the byte array into a byte string again
68 if graph:
69 graph["image"] = bytes(graph["image"])
70
71 return graph
72
73 def version(self):
74 """
75 Returns the version of the daemon
76 """
77 return self.proxy.Version()