Created
July 7, 2016 02:25
-
-
Save sethryder/860f82cd1b8c3aaa3be9aafe462a63e2 to your computer and use it in GitHub Desktop.
Revisions
-
Seth Ryder created this gist
Jul 7, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ 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