Skip to content

Instantly share code, notes, and snippets.

@ulises
Last active August 22, 2016 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulises/0d687bde76d1c6f60f07f620ecd1fe40 to your computer and use it in GitHub Desktop.
Save ulises/0d687bde76d1c6f60f07f620ecd1fe40 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import time
import datetime
import sys
import logging
import flotilla
interval = 60 # report metrics every 60 seconds
hostname = "{{ inventory_hostname }}"
logging.basicConfig(filename='/var/log/plantinator/plantinator.log',
level=logging.DEBUG)
def putval(name, value):
print "PUTVAL %s/weather/gauge-%s interval=%d N:%f" % (hostname,
name,
interval,
value)
now = datetime.datetime.now()
logging.info("%s: PUTVAL %s/weather/gauge-%s interval=%d N:%f" % (now.isoformat(),
hostname,
name,
interval,
value))
client = flotilla.Client()
while not client.ready:
pass
weather = client.first(flotilla.Weather)
light = client.first(flotilla.Light)
colour = client.first(flotilla.Colour)
r = int(colour.red/float(colour.clear)*255.0)
g = int(colour.green/float(colour.clear)*255.0)
b = int(colour.blue/float(colour.clear)*255.0)
putval("temperature", weather.temperature)
# unsure about units, but this is cleary the right scaling
putval("pressure", weather.pressure / 10.0)
putval("lux", light.lux)
putval("red", r)
putval("green", g)
putval("blue", b)
client.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment