]> git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/entropy.py
0fae41559705d7dcba18c6899ecc043dd09a0b74
[collecty.git] / src / collecty / plugins / entropy.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 ..i18n import _
27
28 ENTROPY_FILE = "/proc/sys/kernel/random/entropy_avail"
29
30 class GraphTemplateEntropy(base.GraphTemplate):
31 name = "entropy"
32
33 @property
34 def rrd_graph(self):
35 _ = self.locale.translate
36
37 return [
38 "DEF:entropy=%(file)s:entropy:AVERAGE",
39
40 "LINE3:entropy#ff0000:%-15s" % _("Available entropy"),
41 "VDEF:entrmin=entropy,MINIMUM",
42 "VDEF:entrmax=entropy,MAXIMUM",
43 "VDEF:entravg=entropy,AVERAGE",
44 "GPRINT:entrmax:%12s\:" % _("Maximum") + " %5.0lf",
45 "GPRINT:entrmin:%12s\:" % _("Minimum") + " %5.0lf",
46 "GPRINT:entravg:%12s\:" % _("Average") + " %5.0lf\\n",
47 ]
48
49 lower_limit = 0
50
51 @property
52 def graph_title(self):
53 _ = self.locale.translate
54 return _("Available entropy")
55
56 @property
57 def graph_vertical_label(self):
58 _ = self.locale.translate
59 return _("Bit")
60
61
62 class EntropyObject(base.Object):
63 rrd_schema = [
64 "DS:entropy:GAUGE:0:U",
65 ]
66
67 @property
68 def id(self):
69 return "default"
70
71 def collect(self):
72 with open(ENTROPY_FILE) as f:
73 return f.readline().strip()
74
75
76 class EntropyPlugin(base.Plugin):
77 name = "entropy"
78 description = "Entropy Plugin"
79
80 templates = [GraphTemplateEntropy]
81
82 @property
83 def objects(self):
84 if not os.path.exists(ENTROPY_FILE):
85 self.log.debug(_("Entropy kernel interface does not exist"))
86 return []
87
88 return [EntropyObject(self)]