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 # Convert everything to Celsius
40 "CDEF:value_c=value,273.15,-",
41 "CDEF:critical_c=critical,273.15,-",
42 "CDEF:high_c=high,273.15,-",
43 "CDEF:low_c=low,273.15,-",
45 # Change colour when the value gets above high
46 "CDEF:value_c_high=value_c,high_c,GT,value_c,UNKN,IF",
47 "CDEF:value_c_normal=value_c,high_c,GT,UNKN,value_c,IF",
49 # Get data points for the threshold lines
50 "VDEF:critical_c_line=critical_c,MINIMUM",
51 "VDEF:low_c_line=low_c,MAXIMUM",
53 # Draw the temperature value
54 "LINE3:value_c_high#ff0000",
55 "LINE2:value_c_normal#00ff00:%-15s" % _("Temperature"),
58 "GPRINT:value_c_cur:%10.2lf °C\l",
59 "GPRINT:value_c_avg: %-15s %%6.2lf °C\l" % _("Average"),
60 "GPRINT:value_c_max: %-15s %%6.2lf °C\l" % _("Maximum"),
61 "GPRINT:value_c_min: %-15s %%6.2lf °C\l" % _("Minimum"),
67 "COMMENT:%s\:" % _("Temperature Thresholds"),
68 "HRULE:critical_c_line#000000:%-15s" % _("Critical"),
69 "GPRINT:critical_c_line:%6.2lf °C\\r",
70 "HRULE:low_c_line#0000ff:%-15s" % _("Low"),
71 "GPRINT:low_c_line:%6.2lf °C\\r",
75 def graph_title(self
):
76 _
= self
.locale
.translate
77 return _("Temperature (%s)") % self
.object.sensor
.name
80 def graph_vertical_label(self
):
81 _
= self
.locale
.translate
85 class GraphTemplateSensorsProcessorTemperature(base
.GraphTemplate
):
86 name
= "processor-temperature"
95 def get_temperature_sensors(self
):
96 # Use the coretemp module if available
97 sensors
= self
.plugin
.get_detected_sensor_objects("coretemp-*")
99 # Fall back to the ACPI sensor
101 sensors
= self
.plugin
.get_detected_sensor_objects("acpitz-virtual-*")
105 def get_objects(self
, *args
, **kwargs
):
106 sensors
= self
.get_temperature_sensors()
112 _
= self
.locale
.translate
118 for core
in self
.objects
:
119 id = "core%s" % counter
123 rrd_graph
+= core
.make_rrd_defs(id) + [
124 # Convert everything to celsius
125 "CDEF:%s_value_c=%s_value,273.15,-" % (id, id),
126 "CDEF:%s_critical_c=%s_critical,273.15,-" % (id, id),
127 "CDEF:%s_high_c=%s_high,273.15,-" % (id, id),
130 # Compute the temperature of the processor
131 # by taking the average of all cores
132 all_core_values
= ("%s_value_c" % id for id in ids
)
134 "CDEF:all_value_c=%s,%s,AVG" % (",".join(all_core_values
), len(ids
)),
137 # Get the high threshold of the first core
138 # (assuming that all cores have the same threshold)
140 rrd_graph
.append("CDEF:all_high_c=%s_high_c" % id)
144 # Change colour when the value gets above high
145 "CDEF:all_value_c_high=all_value_c,all_high_c,GT,all_value_c,UNKN,IF",
146 "CDEF:all_value_c_normal=all_value_c,all_high_c,GT,UNKN,all_value_c,IF",
148 "LINE2:all_value_c_high#FF0000",
149 "LINE2:all_value_c_normal#000000:%-15s\l" % _("Temperature"),
151 "GPRINT:all_value_c_avg: %-15s %%6.2lf °C\l" % _("Average"),
152 "GPRINT:all_value_c_max: %-15s %%6.2lf °C\l" % _("Maximum"),
153 "GPRINT:all_value_c_min: %-15s %%6.2lf °C\l" % _("Minimum"),
156 for id, core
, colour
in zip(ids
, self
.objects
, self
.core_colours
):
158 # TODO these lines were supposed to be dashed, but that
159 # didn't really work here
160 "LINE1:%s_value_c%s:%-10s" % (id, colour
, core
.sensor
.label
),
163 # Draw the critical line
166 "HRULE:%s_critical_c_min#000000:%-15s" % (id, _("Critical")),
167 "GPRINT:%s_critical_c_min:%%6.2lf °C\\r" % id,
174 def graph_title(self
):
175 _
= self
.locale
.translate
176 return _("Processor")
179 def graph_vertical_label(self
):
180 _
= self
.locale
.translate
181 return _("Temperature")
184 class SensorBaseObject(base
.Object
):
185 def init(self
, sensor
):
189 return "<%s %s (%s)>" % (self
.__class
__.__name
__, self
.sensor
.name
, self
.sensor
.label
)
193 return "-".join((self
.sensor
.name
, self
.sensor
.label
))
197 return self
.sensor
.type
200 class SensorTemperatureObject(SensorBaseObject
):
202 "DS:value:GAUGE:0:U",
203 "DS:critical:GAUGE:0:U",
209 assert self
.type == "temperature"
221 return self
.sensor
.critical
222 except AttributeError:
228 return self
.sensor
.minimum
229 except AttributeError:
235 return self
.sensor
.high
236 except AttributeError:
240 class SensorVoltageObject(SensorBaseObject
):
242 "DS:value:GAUGE:0:U",
243 "DS:minimum:GAUGE:0:U",
244 "DS:maximum:GAUGE:0:U",
248 assert self
.type == "voltage"
259 return self
.sensor
.minimum
260 except AttributeError:
266 return self
.sensor
.maximum
267 except AttributeError:
271 class SensorFanObject(SensorBaseObject
):
273 "DS:value:GAUGE:0:U",
274 "DS:minimum:GAUGE:0:U",
275 "DS:maximum:GAUGE:0:U",
279 assert self
.type == "fan"
290 return self
.sensor
.minimum
291 except AttributeError:
297 return self
.sensor
.maximum
298 except AttributeError:
302 class SensorsPlugin(base
.Plugin
):
304 description
= "Sensors Plugin"
307 GraphTemplateSensorsProcessorTemperature
,
308 GraphTemplateSensorsTemperature
,
312 # Initialise the sensors library.
313 _collecty
.sensors_init()
316 _collecty
.sensors_cleanup()
320 return self
.get_detected_sensor_objects()
322 def get_detected_sensor_objects(self
, what
=None):
323 for sensor
in _collecty
.get_detected_sensors(what
):
324 if sensor
.type == "temperature":
325 yield SensorTemperatureObject(self
, sensor
)
327 elif sensor
.type == "voltage":
328 yield SensorVoltageObject(self
, sensor
)
330 elif sensor
.type == "fan":
331 yield SensorFanObject(self
, sensor
)