summaryrefslogtreecommitdiff
path: root/envmon/onewire2graphite.py
blob: 46bc94e2003f9f34a8ae70dc696abb79ced227bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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 onewire.SensorNotPresent, e:
            print >>sys.stderr, 'SensorNotPresent:', str(e)
        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()))