3 ###############################################################################
5 # collecty - A system statistics collection daemon for IPFire #
6 # Copyright (C) 2015 IPFire development team #
8 # This program is free software: you can redistribute it and/or modify #
9 # it under the terms of the GNU General Public License as published by #
10 # the Free Software Foundation, either version 3 of the License, or #
11 # (at your option) any later version. #
13 # This program is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU General Public License for more details. #
18 # You should have received a copy of the GNU General Public License #
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
21 ###############################################################################
23 from collecty
import _collecty
31 class GraphTemplateSensorsTemperature(base
.GraphTemplate
):
32 name
= "sensors-temperature"
36 _
= self
.locale
.translate
39 "DEF:value_kelvin=%(file)s:value:AVERAGE",
40 "DEF:critical_kelvin=%(file)s:critical:AVERAGE",
41 "DEF:high_kelvin=%(file)s:high:AVERAGE",
42 "DEF:low_kelvin=%(file)s:low:AVERAGE",
44 # Convert everything to celsius
45 "CDEF:value=value_kelvin,273.15,-",
46 "CDEF:critical=critical_kelvin,273.15,-",
47 "CDEF:high=high_kelvin,273.15,-",
48 "CDEF:low=low_kelvin,273.15,-",
50 # Change colour when the value gets above high
51 "CDEF:value_high=value,high,GT,value,UNKN,IF",
52 "CDEF:value_normal=value,high,GT,UNKN,value,IF",
54 # Get data points for the threshold lines
55 "VDEF:critical_line=critical,MINIMUM",
56 "VDEF:low_line=low,MAXIMUM",
58 # Draw the temperature value
59 "LINE3:value_high#ff0000",
60 "LINE2:value_normal#00ff00:%-15s" % _("Temperature"),
63 "GPRINT:value_cur:%%10.2lf °C\l",
64 "GPRINT:value_avg: %-15s %%6.2lf °C\l" % _("Average"),
65 "GPRINT:value_max: %-15s %%6.2lf °C\l" % _("Maximum"),
66 "GPRINT:value_min: %-15s %%6.2lf °C\l" % _("Minimum"),
72 "COMMENT:%s\:" % _("Temperature Thresholds"),
73 "HRULE:critical_line#000000:%-15s" % _("Critical"),
74 "GPRINT:critical_line:%%6.2lf °C\\r",
75 "HRULE:low_line#0000ff:%-15s" % _("Low"),
76 "GPRINT:low_line:%%6.2lf °C\\r",
80 def graph_title(self
):
81 _
= self
.locale
.translate
82 return _("Temperature (%s)") % self
.object.sensor
.name
85 def graph_vertical_label(self
):
86 _
= self
.locale
.translate
90 class GraphTemplateSensorsProcessorTemperature(base
.GraphTemplate
):
91 name
= "processor-temperature"
94 "core0" : "#ff000033",
95 "core1" : "#0000ff33",
96 "core2" : "#00ff0033",
97 "core3" : "#0000ff33",
100 def get_temperature_sensors(self
):
101 return self
.plugin
.get_detected_sensor_objects("coretemp-*")
103 def get_object_table(self
):
107 for object in self
.get_temperature_sensors():
108 objects_table
["core%s" % counter
] = object
115 _
= self
.locale
.translate
118 cores
= sorted(self
.object_table
.keys())
126 "DEF:value_kelvin_%(core)s=%%(%(core)s)s:value:AVERAGE",
127 "DEF:critical_kelvin_%(core)s=%%(%(core)s)s:critical:AVERAGE",
128 "DEF:high_kelvin_%(core)s=%%(%(core)s)s:high:AVERAGE",
130 # Convert everything to celsius
131 "CDEF:value_%(core)s=value_kelvin_%(core)s,273.15,-",
132 "CDEF:critical_%(core)s=critical_kelvin_%(core)s,273.15,-",
133 "CDEF:high_%(core)s=high_kelvin_%(core)s,273.15,-",
136 rrd_graph
+= [line
% i
for line
in core_graph
]
138 all_core_values
= ("value_%s" % c
for c
in cores
)
139 all_core_highs
= ("high_%s" % c
for c
in cores
)
142 # Compute the temperature of the processor
143 # by taking the average of all cores
144 "CDEF:value=%s,%s,AVG" % (",".join(all_core_values
), len(cores
)),
145 "CDEF:high=%s,MIN" % ",".join(all_core_highs
),
147 # Change colour when the value gets above high
148 "CDEF:value_high=value,high,GT,value,UNKN,IF",
149 "CDEF:value_normal=value,high,GT,UNKN,value,IF",
151 "LINE3:value_high#FF0000",
152 "LINE3:value_normal#000000:%-15s\l" % _("Temperature"),
154 "GPRINT:value_avg: %-15s %%6.2lf °C\l" % _("Average"),
155 "GPRINT:value_max: %-15s %%6.2lf °C\l" % _("Maximum"),
156 "GPRINT:value_min: %-15s %%6.2lf °C\l" % _("Minimum"),
160 object = self
.object_table
.get(core
)
163 "colour" : self
.core_colours
.get(core
, "#000000"),
165 "label" : object.sensor
.label
,
169 # TODO these lines were supposed to be dashed, but that
170 # didn't really work here
171 "LINE2:value_%(core)s%(colour)s:%(label)-10s",
174 rrd_graph
+= [line
% i
for line
in core_graph
]
176 # Draw the critical line
178 "VDEF:critical_line=critical_core0,MINIMUM",
179 "HRULE:critical_line#000000:%-15s" % _("Critical"),
180 "GPRINT:critical_line:%%6.2lf °C\\r",
186 def graph_title(self
):
187 _
= self
.locale
.translate
188 return _("Processor")
191 def graph_vertical_label(self
):
192 _
= self
.locale
.translate
193 return _("Temperature")
196 class SensorBaseObject(base
.Object
):
197 def init(self
, sensor
):
201 return "<%s %s (%s)>" % (self
.__class
__.__name
__, self
.sensor
.name
, self
.sensor
.label
)
205 return "-".join((self
.sensor
.name
, self
.sensor
.label
))
209 return self
.sensor
.type
212 class SensorTemperatureObject(SensorBaseObject
):
214 "DS:value:GAUGE:0:U",
215 "DS:critical:GAUGE:0:U",
221 assert self
.type == "temperature"
233 return self
.sensor
.critical
234 except AttributeError:
240 return self
.sensor
.minimum
241 except AttributeError:
247 return self
.sensor
.high
248 except AttributeError:
252 class SensorVoltageObject(SensorBaseObject
):
254 "DS:value:GAUGE:0:U",
255 "DS:minimum:GAUGE:0:U",
256 "DS:maximum:GAUGE:0:U",
260 assert self
.type == "voltage"
271 return self
.sensor
.minimum
272 except AttributeError:
278 return self
.sensor
.maximum
279 except AttributeError:
283 class SensorFanObject(SensorBaseObject
):
285 "DS:value:GAUGE:0:U",
286 "DS:minimum:GAUGE:0:U",
287 "DS:maximum:GAUGE:0:U",
291 assert self
.type == "fan"
302 return self
.sensor
.minimum
303 except AttributeError:
309 return self
.sensor
.maximum
310 except AttributeError:
314 class SensorsPlugin(base
.Plugin
):
316 description
= "Sensors Plugin"
319 GraphTemplateSensorsProcessorTemperature
,
320 GraphTemplateSensorsTemperature
,
324 # Initialise the sensors library.
325 _collecty
.sensors_init()
328 _collecty
.sensors_cleanup()
332 return self
.get_detected_sensor_objects()
334 def get_detected_sensor_objects(self
, what
=None):
335 for sensor
in _collecty
.get_detected_sensors(what
):
336 if sensor
.type == "temperature":
337 yield SensorTemperatureObject(self
, sensor
)
339 elif sensor
.type == "voltage":
340 yield SensorVoltageObject(self
, sensor
)
342 elif sensor
.type == "fan":
343 yield SensorFanObject(self
, sensor
)