]> git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/loadavg.py
bf9cef2e09f14acdf1da38fc582262736ee9cb39
[collecty.git] / src / collecty / plugins / loadavg.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 os
23
24 from . import base
25
26 from ..colours import *
27 from ..i18n import _
28
29 class GraphTemplateLoadAvg(base.GraphTemplate):
30 name = "loadavg"
31
32 @property
33 def rrd_graph(self):
34 _ = self.locale.translate
35
36 rrd_graph = []
37
38 for id, colour, when in zip(self.object.rrd_schema_names,
39 LOAD_AVG_COLOURS, ("1m", "5m", "15m")):
40 rrd_graph = [
41 "LINE2:%s%s:%-24s" % (id, colour, _("Load Average %s") % when),
42 "GPRINT:%s_max:%12s\: %%6.2lf" % (id, _("Maximum")),
43 "GPRINT:%s_min:%12s\: %%6.2lf" % (id, _("Minimum")),
44 "GPRINT:%s_avg:%12s\: %%6.2lf\l" % (id, _("Average")),
45 ] + rrd_graph
46
47 return rrd_graph
48
49 lower_limit = 0
50
51 @property
52 def graph_title(self):
53 _ = self.locale.translate
54 return _("Load Average")
55
56 @property
57 def graph_vertical_label(self):
58 _ = self.locale.translate
59 return _("Load")
60
61 @property
62 def rrd_graph_args(self):
63 return [
64 "--legend-direction=bottomup",
65 ]
66
67
68 class LoadAvgObject(base.Object):
69 rrd_schema = [
70 "DS:load1:GAUGE:0:U",
71 "DS:load5:GAUGE:0:U",
72 "DS:load15:GAUGE:0:U",
73 ]
74
75 @property
76 def id(self):
77 return "default"
78
79 def collect(self):
80 return os.getloadavg()
81
82
83 class LoadAvgPlugin(base.Plugin):
84 name = "loadavg"
85 description = "Load Average Plugin"
86
87 templates = [GraphTemplateLoadAvg]
88
89 @property
90 def objects(self):
91 return [LoadAvgObject(self)]