forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-example-metrics
executable file
·48 lines (38 loc) · 1.1 KB
/
generate-example-metrics
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
#!/usr/bin/env python
import argparse
import json
import random
import sys
from datetime import datetime
def main():
parser = argparse.ArgumentParser(description='Generate example page request latency metrics.')
parser.add_argument('--count', '-c', type=int, default=25, help='Number of events to generate (negative for unlimited)')
args = parser.parse_args()
count = 0
while args.count < 0 or count < args.count:
timestamp = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
r = random.randint(1, 4)
if r == 1 or r == 2:
page = '/'
elif r == 3:
page = '/list'
else:
page = '/get/' + str(random.randint(1, 99))
server = 'www' + str(random.randint(1, 5)) + '.example.com'
latency = max(1, random.gauss(80, 40))
print(json.dumps({
'timestamp': timestamp,
'metricType': 'request/latency',
'value': int(latency),
# Additional dimensions
'page': page,
'server': server,
'http_method': 'GET',
'http_code': '200',
'unit': 'milliseconds'
}))
count += 1
try:
main()
except KeyboardInterrupt:
sys.exit(1)