forked from wvuong/spring-mvc-bootstrap-angularjs-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregate_metrics.py
99 lines (86 loc) · 3.06 KB
/
aggregate_metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import sys
import urllib2
import json
from collections import defaultdict
from collections import Counter
import numpy
def main(argv):
urls = argv[0:]
counters = Counter()
meters = defaultdict(Counter)
timers = defaultdict(Counter)
for url in urls:
f = urllib2.urlopen(url)
metric = json.loads(f.read())
# merge counters
for counter in metric['counters'].keys():
# see if counter already exists
# print counter
counters[counter] += metric['counters'][counter]['count']
# merge meters
for meter in metric['meters'].keys():
# print meter
meters[meter]['count'] += metric['meters'][meter]['count']
# merge timers
for timer, values in metric['timers'].items():
timers[timer]['count'] += metric['timers'][timer]['count']
timers[timer]['max'] = max(timers[timer]['max'], metric['timers'][timer]['max'])
if timers[timer]['min'] == 0:
timers[timer]['min'] = metric['timers'][timer]['min']
else:
timers[timer]['min'] = min(timers[timer]['min'], metric['timers'][timer]['min'])
if timers[timer]['means'] == 0:
timers[timer]['means'] = []
timers[timer]['p50s'] = []
timers[timer]['p75s'] = []
timers[timer]['p95s'] = []
timers[timer]['p98s'] = []
timers[timer]['p99s'] = []
timers[timer]['p999s'] = []
timers[timer]['weight'] = []
timers[timer]['means'].append(metric['timers'][timer]['mean'])
timers[timer]['p50s'].append(metric['timers'][timer]['p50'])
timers[timer]['p75s'].append(metric['timers'][timer]['p75'])
timers[timer]['p95s'].append(metric['timers'][timer]['p95'])
timers[timer]['p98s'].append(metric['timers'][timer]['p98'])
timers[timer]['p99s'].append(metric['timers'][timer]['p99'])
timers[timer]['p999s'].append(metric['timers'][timer]['p999'])
timers[timer]['weight'].append(metric['timers'][timer]['count'])
timers[timer]['duration_units'] = metric['timers'][timer]['duration_units']
# average timers
for name, timer in timers.items():
timer['mean'] = numpy.average(timer['means'], weights=timer['weight'])
timer['p50'] = numpy.average(timer['p50s'], weights=timer['weight'])
timer['p75'] = numpy.average(timer['p75s'], weights=timer['weight'])
timer['p95'] = numpy.average(timer['p95s'], weights=timer['weight'])
timer['p98'] = numpy.average(timer['p98s'], weights=timer['weight'])
timer['p99'] = numpy.average(timer['p99s'], weights=timer['weight'])
timer['p999'] = numpy.average(timer['p999s'], weights=timer['weight'])
del timer['means']
del timer['p50s']
del timer['p75s']
del timer['p95s']
del timer['p98s']
del timer['p99s']
del timer['p999s']
del timer['weight']
print '=' * 80
print 'COUNTERS'
for k, v in counters.items():
print ' {0}: {1}'.format(k, v)
print
print '=' * 80
print 'METERS'
for key, counter in sorted(meters.items()):
print key
for k, v in counter.items():
print ' {0}: {1}'.format(k, v)
print
print '=' * 80
print 'TIMERS'
for key, counter in sorted(timers.items()):
print key
for k, v in sorted(counter.items()):
print ' {0}: {1}'.format(k, v)
if __name__ == "__main__":
main(sys.argv[1:])