This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Collect data from get_temp.c and set it to StatsD server

By: a guest on Feb 12th, 2013  |  syntax: Python  |  size: 0.79 KB  |  views: 84  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/python2
  2.  
  3. # Collect data from get_temp.c and set it to StatsD server
  4. # get_temp.c = http://pastebin.com/iVwBfbTL
  5. # Copyleft 2013 Chaosdorf
  6.  
  7. import sys
  8. import time
  9. import os
  10. import platform
  11. import subprocess
  12. import socket
  13.  
  14. STATSD_SERVER = 'graphserver.chaosdorf.dn42'
  15. STATSD_PORT = 8125
  16. COMMAND = '/usr/local/bin/get_temp'
  17. DELAY = 1
  18.  
  19. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  20.  
  21. while True:
  22.   now = int( time.time() )
  23.   lines = []
  24.   process = subprocess.Popen(COMMAND, stdout=subprocess.PIPE, shell=True)
  25.   os.waitpid(process.pid, 0)
  26.   temperature = process.stdout.read()
  27.   temperature = float(temperature) / 100.0
  28.   message=("foobar.temperature:%s|g" % temperature)
  29.   print message
  30.   sock.sendto(message, (STATSD_SERVER, STATSD_PORT))
  31.   time.sleep(DELAY)
clone this paste RAW Paste Data