Monitoring and alerting | Raspberry Pi CPU temperature
This is a bare copy of https://github.com/dbrgn/collectd-python-plugins/blob/master/cpu_temp.py
/opt/collectd_plugins/cpu_temp.py
import collectd
PATH = '/sys/class/thermal/thermal_zone0/temp'
def config_func(config):
path_set = False
for node in config.children:
key = node.key.lower()
val = node.values[0]
if key == 'path':
global PATH
PATH = val
path_set = True
else:
collectd.info('cpu_temp plugin: Unknown config key "%s"' % key)
if path_set:
collectd.info('cpu_temp plugin: Using overridden path %s' % PATH)
else:
collectd.info('cpu_temp plugin: Using default path %s' % PATH)
def read_func():
# Read raw value
with open(PATH, 'rb') as f:
temp = f.read().strip()
# Convert to degrees celsius
deg = float(int(temp)) / 1000
# Dispatch value to collectd
val = collectd.Values(type='temperature')
val.plugin = 'cpu_temp'
val.dispatch(values=[deg])
collectd.register_config(config_func)
collectd.register_read(read_func)
Configure collectd
<Plugin python>
ModulePath "/opt/collectd_plugins"
Import "cpu_temp"
<Module cpu_temp>
</Module>
</Plugin>
Grafana query from InfluxDB
SELECT last(value) FROM "cpu_temp_value" WHERE "type" = 'temperature' AND "host" =~ /^$host$/ AND $timeFilter GROUP BY time($interval)
The CPU temperature is also monitored by Repetier Server integrated monitoring
Keine Kommentare vorhanden
Keine Kommentare vorhanden