Refactor to use wildcard/exclusion for all

(imported from commit 2874361aef2cbc14a3047f964eb584f27a29323c)
This commit is contained in:
Leo Franchi
2013-05-30 11:43:27 -04:00
committed by Tim Abbott
parent 5f86ed92f3
commit b6a3446b62

View File

@@ -22,6 +22,22 @@ def extract_json_response(resp):
else:
return resp.json
def get_data_url(buckets, realm):
realm_key = statsd_key(realm, True)
# This is the slightly-cleaned up JSON api version of https://graphiti.humbughq.com/graphs/945c7aafc2d
#
# Fetches 1 month worth of data
DATA_URL="https://graphite.humbughq.com/render/?from=-28d&format=json"
for bucket in buckets:
if realm != 'all':
statsd_target = "stats.gauges.staging.users.active.%s.%s" % (realm_key, bucket)
DATA_URL += "&target=%s" % (statsd_target,)
else:
# all means adding up all realms, but exclude the .all. metrics since that would double things
DATA_URL += "&target=sum(exclude(stats.gauges.staging.users.active.*.%s, 'all'))" % (bucket,)
return DATA_URL
def get_data(url, username, pw):
from requests.auth import HTTPDigestAuth
@@ -60,7 +76,6 @@ def percent_diff(prev, cur):
def parse_data(data, today):
for metric in data:
# print "Got %s with data points %s" % (metric['target'], len(metric['datapoints']))
if metric['target'] in statsd_targets:
# Calculate % between peak 2hr and 10min across each day and week
metric['datapoints'].sort(key=lambda p: p[1])
@@ -123,11 +138,7 @@ if __name__ == '__main__':
# This is the slightly-cleaned up JSON api version of https://graphiti.humbughq.com/graphs/945c7aafc2d
#
# Fetches 1 month worth of data
DATA_URL="https://graphite.humbughq.com/render/?from=-28d&format=json"
statsd_targets = ["stats.gauges.staging.users.active.%s.%s" % (realm_key, bucket) for bucket in buckets]
for target in statsd_targets:
DATA_URL += "&target=%s" % (target,)
DATA_URL = get_data_url(buckets, options.realm)
data = get_data(DATA_URL, options.user, options.password)