Created
June 2, 2016 17:06
-
-
Save toni-moreno/fa174cc1bb38f7178afa09305f3c5397 to your computer and use it in GitHub Desktop.
This file contains 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 urllib | |
import urllib2 | |
import random | |
import sys | |
import json | |
import time | |
import pprint | |
datafrom = '-12hours' | |
delay = 0.3 | |
def load_metric(metric): | |
url = 'http://graphitetst.mydomain/render' | |
user_agent = 'GRAPHITE STRESSER' | |
values = {'from' : datafrom, | |
'format' : 'json', | |
'target' : metric } | |
headers = { 'User-Agent' : user_agent } | |
data = urllib.urlencode(values) | |
req = urllib2.Request(url, data, headers) | |
try: | |
r = urllib2.urlopen(req) | |
except HTTPError, e: | |
print 'The server couldn\'t fulfill the request.' | |
print 'Error code: ', e.code | |
except URLError, e: | |
print 'We failed to reach a server.' | |
print 'Reason: ', e.reason | |
else: | |
the_page = r.read() | |
return the_page | |
with open('/tmp/metric_list.txt') as f: | |
content = f.read().splitlines() | |
alen = len(content) | |
while True: | |
num = random.randint(0,alen-1) | |
start_time = time.time() | |
metric_data_raw=load_metric(content[num]) | |
elapsed_time = time.time() - start_time | |
outlen=len(metric_data_raw) | |
formatted_time=time.asctime(time.localtime(start_time)) | |
if outlen < 20: | |
print "[",formatted_time,"] ERROR in ", content[num] , "incorrect data length:", outlen , "elapsed time: ", elapsed_time | |
continue | |
metric_data=json.loads(metric_data_raw) | |
#ts_len=len(metric_data.datapoints) | |
#pprint.pprint(metric_data) | |
md=metric_data[0]; | |
dp=md['datapoints'] | |
name=md['target'] | |
dp_len=len(dp) | |
nulls = 0 | |
for i in reversed(dp): | |
t = str(i[0]) | |
if t.strip() == 'None': | |
nulls = nulls + 1 | |
else: | |
break | |
#print dp | |
print "[",formatted_time,"] OK METRIC: " , name, len(dp) , "nulls:" , nulls , "elapsed time: ", elapsed_time | |
time.sleep(delay) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment