Skip to content

Instantly share code, notes, and snippets.

@sethryder
Created July 7, 2016 02:25
Show Gist options
  • Select an option

  • Save sethryder/860f82cd1b8c3aaa3be9aafe462a63e2 to your computer and use it in GitHub Desktop.

Select an option

Save sethryder/860f82cd1b8c3aaa3be9aafe462a63e2 to your computer and use it in GitHub Desktop.

Revisions

  1. Seth Ryder created this gist Jul 7, 2016.
    26 changes: 26 additions & 0 deletions cachet_lambda.py
    Original 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