Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Created September 28, 2012 18:34
Show Gist options
  • Save lvidarte/3801419 to your computer and use it in GitHub Desktop.
Save lvidarte/3801419 to your computer and use it in GitHub Desktop.
Sending data to cosm.com
#!/usr/bin/python2.7
import json
import httplib
API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
loadavg = open('/proc/loadavg').read().split()
data = {'datastreams': [
{'id': '1-minute', 'current_value': loadavg[0]},
{'id': '5-minutes', 'current_value': loadavg[1]},
{'id': '15-minutes', 'current_value': loadavg[2]},
]}
str_data = json.dumps(data)
conn = httplib.HTTPConnection('api.cosm.com')
conn.request('PUT', '/v2/feeds/77829', str_data, {'X-ApiKey': API_KEY})
res = conn.getresponse()
print res.status, res.reason
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment