]>
git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/psi.py
8f326c1572c652d8b55810dd68a02c38849aa8a0
2 ###############################################################################
4 # collecty - A system statistics collection daemon for IPFire #
5 # Copyright (C) 2021 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 ###############################################################################
25 from ..colours
import *
26 from ..constants
import *
29 class PSIGraphTemplate(base
.GraphTemplate
):
35 "LINE2:some_avg300%s:%s" % (
36 YELLOW
, LABEL
% _("5 Minutes"),
38 "GPRINT:some_avg300_cur:%s" % FLOAT
,
39 "GPRINT:some_avg300_avg:%s" % FLOAT
,
40 "GPRINT:some_avg300_min:%s" % FLOAT
,
41 "GPRINT:some_avg300_max:%s\\j" % FLOAT
,
43 "LINE2:some_avg60%s:%s" % (
44 ORANGE
, LABEL
% _("1 Minute"),
46 "GPRINT:some_avg60_cur:%s" % FLOAT
,
47 "GPRINT:some_avg60_avg:%s" % FLOAT
,
48 "GPRINT:some_avg60_min:%s" % FLOAT
,
49 "GPRINT:some_avg60_max:%s\\j" % FLOAT
,
51 "LINE2:some_avg10%s:%s" % (
52 RED
, LABEL
% _("10 Seconds"),
54 "GPRINT:some_avg10_cur:%s" % FLOAT
,
55 "GPRINT:some_avg10_avg:%s" % FLOAT
,
56 "GPRINT:some_avg10_min:%s" % FLOAT
,
57 "GPRINT:some_avg10_max:%s\\j" % FLOAT
,
60 "COMMENT:%s" % EMPTY_LABEL
,
61 "COMMENT:%s" % (COLUMN
% _("Current")),
62 "COMMENT:%s" % (COLUMN
% _("Average")),
63 "COMMENT:%s" % (COLUMN
% _("Minimum")),
64 "COMMENT:%s\\j" % (COLUMN
% _("Maximum")),
73 def graph_title(self
):
75 "cpu" : _("Processor Pressure Stall Information"),
76 "io" : _("Input/Output Pressure Stall Information"),
77 "memory" : _("Memory Pressure Stall Information"),
81 return titles
[self
.object.id]
83 return _("%s Pressure Stall Information") % self
.object.id
86 def graph_vertical_label(self
):
87 return _("Percentage")
90 def rrd_graph_args(self
):
92 "--legend-direction=bottomup",
96 class PSIObject(base
.Object
):
99 "DS:some_avg10:GAUGE:0:100",
100 "DS:some_avg60:GAUGE:0:100",
101 "DS:some_avg300:GAUGE:0:100",
102 "DS:some_total:DERIVE:0:U",
105 "DS:full_avg10:GAUGE:0:100",
106 "DS:full_avg60:GAUGE:0:100",
107 "DS:full_avg300:GAUGE:0:100",
108 "DS:full_total:DERIVE:0:U",
112 return "<%s %s>" % (self
.__class
__.__name
__, self
.item
)
114 def init(self
, item
):
117 self
.path
= os
.path
.join("/proc/pressure", self
.item
)
124 lines
= self
.read_file("/proc/pressure", self
.item
)
126 # Do nothing if nothing could be read
130 # Parse all input lines
132 for line
in lines
.splitlines():
133 values
.update(self
._parse
_psi
(line
))
135 # Return all values in order
136 for share
in ("some", "full"):
137 for value
in ("avg10", "avg60", "avg300", "total"):
138 yield values
.get("%s-%s" % (share
, value
), None)
140 def _parse_psi(self
, line
):
141 words
= line
.split(" ")
146 for i
, word
in enumerate(words
):
147 # Store the share of time
153 key
, delim
, value
= word
.partition("=")
155 # Store it in the values array
156 values
["%s-%s" % (share
, key
)] = value
162 class PSIPlugin(base
.Plugin
):
164 description
= "Pressure Stall Information Plugin"
172 for item
in os
.listdir("/proc/pressure"):
173 yield PSIObject(self
, item
)