Skip to content

Instantly share code, notes, and snippets.

@sethryder
Created July 7, 2016 02:25
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 sethryder/860f82cd1b8c3aaa3be9aafe462a63e2 to your computer and use it in GitHub Desktop.
Save sethryder/860f82cd1b8c3aaa3be9aafe462a63e2 to your computer and use it in GitHub Desktop.
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