Created
July 7, 2016 02:25
-
-
Save sethryder/860f82cd1b8c3aaa3be9aafe462a63e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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