Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import requests
import time
import json
checks = {}
api_key = ''
api_endpoint = ''
checks['google'] = {'metric_id': 1, 'url': 'http://www.google.com'}
checks['github'] = {'metric_id': 2, 'url': 'http://www.github.com'}
for check in checks.itervalues():
metric_id = str(check['metric_id'])
start = time.time()
r = requests.get(check['url'])
r.content # wait until full content has been transfered
roundtrip = int((time.time() - start) * 1000)
post_headers = {'user-agent': 'cachet-lamba/0.0.1', 'Content-Type': 'application/json', 'X-Cachet-Token': api_key }
post_url = api_endpoint + '/metrics/' + metric_id + '/points'
post_data = {'id': metric_id, 'value': roundtrip }
r = requests.post(post_url, data = json.dumps(post_data), headers = post_headers)
print "Finished check of " + check['url'] + ', responded in ' + str(roundtrip) + 'ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment