Created
May 2, 2016 22:42
-
-
Save eishay/1a3908557812c569ba24a4a695d9d503 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 pycurl | |
import os | |
import socket | |
from urllib import pathname2url | |
import json | |
import urllib2 | |
# in this specific case we take an average over two hours of the mean(99) of statsd label named "some.thing.total" | |
target=pathname2url('summarize(stats.timers.some.thing.total.mean_99,"2hour","avg")') | |
# using hosted graphite's service to get the json. Note the "format=json" | |
data=urllib2.urlopen('https://www.hostedgraphite.com/account-id/metric-group-id/graphite/render/?from=-2h&target='+target+'&format=json') | |
stats = json.load(data) | |
# getting the latest data point from the json | |
my_time = stats[0]['datapoints'][1][0] | |
URL = "http://api.copperegg.com/v2/revealmetrics/samples/my_time.json" | |
userPasswd = "XXXXXXXXXXX:U" | |
postdata = {"identifier": "my_server", "timestamp": int(time.time()), "values": {"my_time": my_time}} | |
c = pycurl.Curl() | |
c.setopt(c.URL, URL) | |
c.setopt(c.POST, 1) | |
c.setopt(c.POSTFIELDS, str(postdata)) | |
c.setopt(c.HTTPHEADER, ["Content-Type: application/json"]) | |
c.setopt(c.HTTPAUTH, c.HTTPAUTH_BASIC) | |
c.setopt(c.USERPWD, userPasswd) | |
c.setopt(c.VERBOSE, 1) | |
try: | |
c.perform() | |
except: | |
print "Error performing curl perform" | |
c.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment