Last active
December 28, 2015 15:19
-
-
Save n-st/7520829 to your computer and use it in GitHub Desktop.
Munin plugin that reads any number of DS18B20 temperature sensors using the w1-gpio and w1_therm kernel modules.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import os | |
import re | |
from syslog import syslog | |
temperatureRegex = r't=(-?\d+)' | |
sensorNames = { | |
'28-00000551b94b': 'Room temperature' | |
} | |
def getSensors(): | |
return [x for x in os.listdir('/sys/bus/w1/devices/') if x.startswith('28-')] | |
if len(sys.argv) == 2 and sys.argv[1] == "autoconf": | |
print "yes" | |
elif len(sys.argv) == 2 and sys.argv[1] == "config": | |
print 'graph_title External temperature sensors' | |
print 'graph_vlabel degrees Celsius' | |
print 'graph_category sensors' | |
for sensor in getSensors(): | |
if sensor in sensorNames: | |
print 'sensor_%s.label %s' % (sensor, sensorNames[sensor]) | |
else: | |
print 'sensor_%s.label %s' % (sensor, sensor) | |
print 'sensor_%s.type GAUGE' % (sensor) | |
else: | |
for sensor in getSensors(): | |
for i in range(3): | |
rawData = open('/sys/bus/w1/devices/'+sensor+'/w1_slave', 'r').read() | |
syslog('Sensor %s, try %s: %s' % (sensor, i + 1, ' / '.join(rawData.splitlines()))) | |
if 'YES' in rawData: | |
occurences = re.findall(temperatureRegex, rawData) | |
if occurences[0] is not None: | |
millidegrees = int(occurences[0]) | |
print('sensor_%s.value %s' % (sensor, float(millidegrees) / 1000)) | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment