]> git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/loadavg.py
psi: Add graph template
[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 ..constants import *
28 from ..i18n import _
29
30 class GraphTemplateLoadAvg(base.GraphTemplate):
31 name = "loadavg"
32
33 @property
34 def rrd_graph(self):
35 rrd_graph = [
36 "LINE2:load15%s:%s" % (
37 YELLOW, LABEL % _("15 Minutes"),
38 ),
39 "GPRINT:load15_cur:%s" % FLOAT,
40 "GPRINT:load15_avg:%s" % FLOAT,
41 "GPRINT:load15_min:%s" % FLOAT,
42 "GPRINT:load15_max:%s\\j" % FLOAT,
43
44 "LINE2:load5%s:%s" % (
45 ORANGE, LABEL % _("5 Minutes"),
46 ),
47 "GPRINT:load5_cur:%s" % FLOAT,
48 "GPRINT:load5_avg:%s" % FLOAT,
49 "GPRINT:load5_min:%s" % FLOAT,
50 "GPRINT:load5_max:%s\\j" % FLOAT,
51
52 "LINE2:load1%s:%s" % (
53 RED, LABEL % _("1 Minute"),
54 ),
55 "GPRINT:load1_cur:%s" % FLOAT,
56 "GPRINT:load1_avg:%s" % FLOAT,
57 "GPRINT:load1_min:%s" % FLOAT,
58 "GPRINT:load1_max:%s\\j" % FLOAT,
59
60 # Headline
61 "COMMENT:%s" % EMPTY_LABEL,
62 "COMMENT:%s" % (COLUMN % _("Current")),
63 "COMMENT:%s" % (COLUMN % _("Average")),
64 "COMMENT:%s" % (COLUMN % _("Minimum")),
65 "COMMENT:%s\\j" % (COLUMN % _("Maximum")),
66 ]
67
68 return rrd_graph
69
70 lower_limit = 0
71
72 @property
73 def graph_title(self):
74 return _("Load Average")
75
76 @property
77 def graph_vertical_label(self):
78 return _("Load")
79
80 @property
81 def rrd_graph_args(self):
82 return [
83 "--legend-direction=bottomup",
84 ]
85
86
87 class LoadAvgObject(base.Object):
88 rrd_schema = [
89 "DS:load1:GAUGE:0:U",
90 "DS:load5:GAUGE:0:U",
91 "DS:load15:GAUGE:0:U",
92 ]
93
94 @property
95 def id(self):
96 return "default"
97
98 def collect(self):
99 return os.getloadavg()
100
101
102 class LoadAvgPlugin(base.Plugin):
103 name = "loadavg"
104 description = "Load Average Plugin"
105
106 templates = [GraphTemplateLoadAvg]
107
108 @property
109 def objects(self):
110 return [LoadAvgObject(self)]