mirror of https://github.com/apache/druid.git
66 lines
1.9 KiB
Python
Executable File
66 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
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)
|