diff options
author | Christian Franke <nobody@nowhere.ws> | 2013-06-20 19:45:37 +0200 |
---|---|---|
committer | Christian Franke <nobody@nowhere.ws> | 2013-06-20 20:02:39 +0200 |
commit | 8f0bf68698637adfa167549c2d6293293d769c06 (patch) | |
tree | b54cd6d9f43b65541eda0b24e63cae7efe382ac6 | |
parent | b0b4edf703fd03b42bb737d0c2a1a8b6c2d018b0 (diff) |
envmon: add graphite target
-rwxr-xr-x | envmon/onewire2graphite.py | 30 | ||||
-rwxr-xr-x | envmon/outdoor2graphite.py | 35 |
2 files changed, 65 insertions, 0 deletions
diff --git a/envmon/onewire2graphite.py b/envmon/onewire2graphite.py new file mode 100755 index 0000000..73e6b8d --- /dev/null +++ b/envmon/onewire2graphite.py @@ -0,0 +1,30 @@ +#!/usr/bin/python + +import time +import sys + +import onewire +import socket + +CARBON_SERVER = 'sonar.local.sublab.org' +CARBON_PORT = 2003 + +prefix = "envmon.beaglebone_local_sublab_org." + +sock = socket.socket() +sock.connect((CARBON_SERVER, CARBON_PORT)) + +while True: + message = '' + for sensor in onewire.sensors(): + try: + message += "%s %f %d\n" % (prefix + sensor, onewire.sensor(sensor).temperature, time.time()) + except Exception: + print >>sys.stderr, "On %s: Could not retrieve temperature for '%s':" % ( + time.strftime('%a, %d %b %Y %T %z'), sensor) + sys.excepthook(*sys.exc_info()) + print >>sys.stderr, '========================================' + if message: + print message + sock.sendall(message) + time.sleep(300-len(onewire.sensors())) diff --git a/envmon/outdoor2graphite.py b/envmon/outdoor2graphite.py new file mode 100755 index 0000000..de58698 --- /dev/null +++ b/envmon/outdoor2graphite.py @@ -0,0 +1,35 @@ +#!/usr/bin/python + +import time +import sys + +import socket + +import weather + +location = '20065491' # Leipzig + +CARBON_SERVER = 'sonar.local.sublab.org' +CARBON_PORT = 2003 + +prefix = "envmon.beaglebone_local_sublab_org." + +sock = socket.socket() +sock.connect((CARBON_SERVER, CARBON_PORT)) + +while True: + message = '' + try: + data = weather.weather(location) + message += '%s %s %d\n' % (prefix + 'outside', + data.temperature, + time.time()) + except Exception: + sys.stderr.write('Exception occured at %s:\n' % time.strftime('%a, %d %b %Y %T %z')) + sys.excepthook(*sys.exc_info()) + sys.stderr.write('========================================\n') + time.sleep(60) + else: + sock.sendall(message) + time.sleep(300) + |