#!/usr/bin/python2 # Collect data from get_temp.c and set it to StatsD server # get_temp.c = http://pastebin.com/iVwBfbTL # Copyleft 2013 Chaosdorf import sys import time import os import platform import subprocess import socket STATSD_SERVER = 'graphserver.chaosdorf.dn42' STATSD_PORT = 8125 COMMAND = '/usr/local/bin/get_temp' DELAY = 1 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) while True: now = int( time.time() ) lines = [] process = subprocess.Popen(COMMAND, stdout=subprocess.PIPE, shell=True) os.waitpid(process.pid, 0) temperature = process.stdout.read() temperature = float(temperature) / 100.0 message=("foobar.temperature:%s|g" % temperature) print message sock.sendto(message, (STATSD_SERVER, STATSD_PORT)) time.sleep(DELAY)