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 ###############################################################################
26 from .. import _collecty
29 class GraphTemplateSensorsTemperature(base
.GraphTemplate
):
30 name
= "sensors-temperature"
34 _
= self
.locale
.translate
37 # Convert everything to Celsius
38 "CDEF:value_c=value,273.15,-",
39 "CDEF:critical_c=critical,273.15,-",
40 "CDEF:high_c=high,273.15,-",
41 "CDEF:low_c=low,273.15,-",
43 # Change colour when the value gets above high
44 "CDEF:value_c_high=value_c,high_c,GT,value_c,UNKN,IF",
45 "CDEF:value_c_normal=value_c,high_c,GT,UNKN,value_c,IF",
47 # Get data points for the threshold lines
48 "VDEF:critical_c_line=critical_c,MINIMUM",
49 "VDEF:low_c_line=low_c,MAXIMUM",
51 # Draw the temperature value
52 "LINE3:value_c_high#ff0000",
53 "LINE2:value_c_normal#00ff00:%-15s" % _("Temperature"),
56 "GPRINT:value_c_cur:%10.2lf °C\l",
57 "GPRINT:value_c_avg: %-15s %%6.2lf °C" % _("Average"),
58 "GPRINT:value_c_max: %-15s %%6.2lf °C" % _("Maximum"),
59 "GPRINT:value_c_min: %-15s %%6.2lf °C" % _("Minimum"),
65 "COMMENT:%s\:" % _("Temperature Thresholds"),
66 "HRULE:critical_c_line#000000:%-15s" % _("Critical"),
67 "GPRINT:critical_c_line:%6.2lf °C\\r",
68 "HRULE:low_c_line#0000ff:%-15s" % _("Low"),
69 "GPRINT:low_c_line:%6.2lf °C\\r",
73 def graph_title(self
):
74 _
= self
.locale
.translate
75 return _("Temperature (%s)") % self
.object.sensor
.name
78 def graph_vertical_label(self
):
79 _
= self
.locale
.translate
83 class GraphTemplateSensorsProcessorTemperature(base
.GraphTemplate
):
84 name
= "processor-temperature"
93 def get_temperature_sensors(self
):
94 # Use the coretemp module if available
95 sensors
= self
.plugin
.get_detected_sensor_objects("coretemp-*")
97 # Fall back to the ACPI sensor
99 sensors
= self
.plugin
.get_detected_sensor_objects("acpitz-virtual-*")
103 def get_objects(self
, *args
, **kwargs
):
104 sensors
= self
.get_temperature_sensors()
110 _
= self
.locale
.translate
116 for core
in self
.objects
:
117 id = "core%s" % counter
121 rrd_graph
+= core
.make_rrd_defs(id) + [
122 # Convert everything to celsius
123 "CDEF:%s_value_c=%s_value,273.15,-" % (id, id),
124 "CDEF:%s_critical_c=%s_critical,273.15,-" % (id, id),
125 "CDEF:%s_high_c=%s_high,273.15,-" % (id, id),
128 # Compute the temperature of the processor
129 # by taking the average of all cores
130 all_core_values
= ("%s_value_c" % id for id in ids
)
132 "CDEF:all_value_c=%s,%s,AVG" % (",".join(all_core_values
), len(ids
)),
135 # Get the high threshold of the first core
136 # (assuming that all cores have the same threshold)
138 rrd_graph
.append("CDEF:all_high_c=%s_high_c" % id)
142 # Change colour when the value gets above high
143 "CDEF:all_value_c_high=all_value_c,all_high_c,GT,all_value_c,UNKN,IF",
144 "CDEF:all_value_c_normal=all_value_c,all_high_c,GT,UNKN,all_value_c,IF",
146 "LINE2:all_value_c_high#FF0000",
147 "LINE2:all_value_c_normal#000000:%-15s" % _("Temperature"),
149 "GPRINT:all_value_c_avg: %-15s %%6.2lf °C" % _("Average"),
150 "GPRINT:all_value_c_max: %-15s %%6.2lf °C" % _("Maximum"),
151 "GPRINT:all_value_c_min: %-15s %%6.2lf °C" % _("Minimum"),
154 for id, core
, colour
in zip(ids
, self
.objects
, self
.core_colours
):
156 # TODO these lines were supposed to be dashed, but that
157 # didn't really work here
158 "LINE1:%s_value_c%s:%-10s" % (id, colour
, core
.sensor
.label
),
161 # Draw the critical line
164 "HRULE:%s_critical_c_min#000000:%-15s" % (id, _("Critical")),
165 "GPRINT:%s_critical_c_min:%%6.2lf °C\\r" % id,
172 def graph_title(self
):
173 _
= self
.locale
.translate
174 return _("Processor")
177 def graph_vertical_label(self
):
178 _
= self
.locale
.translate
179 return _("Temperature")
182 class SensorBaseObject(base
.Object
):
183 def init(self
, sensor
):
187 return "<%s %s (%s)>" % (self
.__class
__.__name
__, self
.sensor
.name
, self
.sensor
.label
)
191 return "-".join((self
.sensor
.name
, self
.sensor
.label
))
195 return self
.sensor
.type
198 class SensorTemperatureObject(SensorBaseObject
):
200 "DS:value:GAUGE:0:U",
201 "DS:critical:GAUGE:0:U",
207 assert self
.type == "temperature"
219 return self
.sensor
.critical
220 except AttributeError:
226 return self
.sensor
.minimum
227 except AttributeError:
233 return self
.sensor
.high
234 except AttributeError:
238 class SensorVoltageObject(SensorBaseObject
):
240 "DS:value:GAUGE:0:U",
241 "DS:minimum:GAUGE:0:U",
242 "DS:maximum:GAUGE:0:U",
246 assert self
.type == "voltage"
257 return self
.sensor
.minimum
258 except AttributeError:
264 return self
.sensor
.maximum
265 except AttributeError:
269 class SensorFanObject(SensorBaseObject
):
271 "DS:value:GAUGE:0:U",
272 "DS:minimum:GAUGE:0:U",
273 "DS:maximum:GAUGE:0:U",
277 assert self
.type == "fan"
288 return self
.sensor
.minimum
289 except AttributeError:
295 return self
.sensor
.maximum
296 except AttributeError:
300 class SensorsPlugin(base
.Plugin
):
302 description
= "Sensors Plugin"
305 GraphTemplateSensorsProcessorTemperature
,
306 GraphTemplateSensorsTemperature
,
310 # Initialise the sensors library.
311 _collecty
.sensors_init()
314 _collecty
.sensors_cleanup()
318 return self
.get_detected_sensor_objects()
320 def get_detected_sensor_objects(self
, what
=None):
321 for sensor
in _collecty
.get_detected_sensors(what
):
322 if sensor
.type == "temperature":
323 yield SensorTemperatureObject(self
, sensor
)
325 elif sensor
.type == "voltage":
326 yield SensorVoltageObject(self
, sensor
)
328 elif sensor
.type == "fan":
329 yield SensorFanObject(self
, sensor
)