2022-05-11 04:58:32 +00:00
|
|
|
#! /usr/bin/env python3
|
2014-03-22 04:18:54 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import uuid
|
|
|
|
import shutil
|
|
|
|
import random
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
SYSLOG_DATE_FMT = "%b %d %H:%M:%S"
|
|
|
|
ACCESS_LOG_DATE_FMT = "%d/%b/%Y:%H:%M:%S"
|
|
|
|
GENERIC_DATE_FMT = "%Y-%m-%dT%H:%M:%S.%%s"
|
|
|
|
|
2022-08-30 23:11:37 +00:00
|
|
|
TEST_ADDRESSES = (
|
|
|
|
["192.0.2.55"] * 20 +
|
|
|
|
["192.0.2.44"] * 20 +
|
|
|
|
["192.0.2.3"] * 40 +
|
|
|
|
["192.0.2.100"] * 10 +
|
|
|
|
["192.0.2.122"] * 30 +
|
|
|
|
["192.0.2.42"] * 100
|
|
|
|
)
|
2014-03-22 04:18:54 +00:00
|
|
|
|
|
|
|
TEST_USERNAMES = [
|
|
|
|
"bob@example.com",
|
2022-08-30 23:11:37 +00:00
|
|
|
"bob@example.com",
|
|
|
|
"bob@example.com",
|
|
|
|
"combatcarl@example.com",
|
|
|
|
"combatcarl@example.com",
|
|
|
|
"combatcarl@example.com",
|
|
|
|
"combatcarl@example.com",
|
|
|
|
"combatcarl@example.com",
|
|
|
|
"combatcarl@example.com",
|
2014-03-22 04:18:54 +00:00
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
]
|
|
|
|
|
|
|
|
TEST_METHODS = [
|
|
|
|
"GET",
|
|
|
|
"GET",
|
|
|
|
"GET",
|
|
|
|
"GET",
|
|
|
|
"GET",
|
|
|
|
"GET",
|
|
|
|
"PUT",
|
|
|
|
]
|
|
|
|
|
2022-08-30 23:11:37 +00:00
|
|
|
PATH_COMPS = "Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua".split()
|
|
|
|
|
2014-03-22 04:18:54 +00:00
|
|
|
TEST_URLS = [
|
|
|
|
"/index.html",
|
|
|
|
"/index.html",
|
|
|
|
"/index.html",
|
|
|
|
"/features.html",
|
|
|
|
"/images/compass.jpg",
|
|
|
|
"/obj/1234",
|
|
|
|
"/obj/1235?foo=bar",
|
|
|
|
"/obj/1236?search=demo&start=1",
|
|
|
|
]
|
|
|
|
|
2022-08-30 23:11:37 +00:00
|
|
|
for index in range(0, 50):
|
|
|
|
path_list = []
|
|
|
|
for count in range(random.randint(2, 8)):
|
|
|
|
path_list.append(random.choice(PATH_COMPS))
|
|
|
|
TEST_URLS.append("/".join(path_list))
|
|
|
|
|
2014-03-22 04:18:54 +00:00
|
|
|
TEST_VERSIONS = [
|
|
|
|
"HTTP/1.0",
|
|
|
|
"HTTP/1.0",
|
|
|
|
"HTTP/1.1",
|
|
|
|
]
|
|
|
|
|
|
|
|
TEST_STATUS = [
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
404,
|
2022-08-30 23:11:37 +00:00
|
|
|
404,
|
|
|
|
404,
|
|
|
|
404,
|
|
|
|
403,
|
|
|
|
403,
|
|
|
|
403,
|
2014-03-22 04:18:54 +00:00
|
|
|
500
|
|
|
|
]
|
|
|
|
|
|
|
|
TEST_REFERRERS = [
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"http://lnav.org/download.html",
|
|
|
|
]
|
|
|
|
|
|
|
|
TEST_AGENTS = [
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"-",
|
|
|
|
"Apache-HttpClient/4.2.3 (java 1.5)",
|
|
|
|
"Apache-HttpClient/4.2.3 (java 1.5)",
|
|
|
|
"Apache-HttpClient/4.2.3 (java 1.5)",
|
|
|
|
"Apache-HttpClient/4.2.3 (java 1.5)",
|
|
|
|
"Apache-HttpClient/4.2.3 (java 1.5)",
|
2022-08-30 23:11:37 +00:00
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
|
|
|
|
"Roku4640X/DVP-7.70 (297.70E04154A)",
|
|
|
|
"Roku4640X/DVP-7.70 (297.70E04154A)",
|
|
|
|
"Roku4640X/DVP-7.70 (297.70E04154A)",
|
2014-03-22 04:18:54 +00:00
|
|
|
]
|
|
|
|
|
2023-08-23 06:09:51 +00:00
|
|
|
START_TIME = datetime.datetime.fromtimestamp(1692700000)
|
2022-08-30 23:11:37 +00:00
|
|
|
ACCESS_LOG_CURR_TIME = START_TIME
|
|
|
|
SYSLOG_LOG_CURR_TIME = START_TIME
|
|
|
|
|
|
|
|
|
2014-03-22 04:18:54 +00:00
|
|
|
def access_log_msgs():
|
2022-08-30 23:11:37 +00:00
|
|
|
global ACCESS_LOG_CURR_TIME
|
2014-03-22 04:18:54 +00:00
|
|
|
while True:
|
2023-08-23 06:09:51 +00:00
|
|
|
ACCESS_LOG_CURR_TIME += datetime.timedelta(seconds=random.randrange(1, 5))
|
2014-03-22 04:18:54 +00:00
|
|
|
yield '%s - %s [%s +0000] "%s %s %s" %s %s "%s" "%s"\n' % (
|
|
|
|
random.choice(TEST_ADDRESSES),
|
|
|
|
random.choice(TEST_USERNAMES),
|
2022-08-30 23:11:37 +00:00
|
|
|
ACCESS_LOG_CURR_TIME.strftime(ACCESS_LOG_DATE_FMT),
|
2014-03-22 04:18:54 +00:00
|
|
|
random.choice(TEST_METHODS),
|
|
|
|
random.choice(TEST_URLS),
|
|
|
|
random.choice(TEST_VERSIONS),
|
|
|
|
random.choice(TEST_STATUS),
|
2022-08-30 23:11:37 +00:00
|
|
|
int(random.lognormvariate(1, 1) * 1000),
|
2014-03-22 04:18:54 +00:00
|
|
|
random.choice(TEST_REFERRERS),
|
|
|
|
random.choice(TEST_AGENTS)
|
2022-08-30 23:11:37 +00:00
|
|
|
)
|
|
|
|
|
2014-03-22 04:18:54 +00:00
|
|
|
|
|
|
|
TEST_PROCS = [
|
|
|
|
"server[123]",
|
|
|
|
"server[123]",
|
|
|
|
"server[123]",
|
|
|
|
"server[121]",
|
|
|
|
"server[124]",
|
|
|
|
"server[123]",
|
|
|
|
"worker[61456]",
|
|
|
|
"worker[61456]",
|
|
|
|
"worker[61457]",
|
|
|
|
]
|
|
|
|
|
|
|
|
TEST_MSGS = [
|
|
|
|
"Handling request %s" % uuid.uuid4(),
|
|
|
|
"Handling request %s" % uuid.uuid4(),
|
|
|
|
"Handling request %s" % uuid.uuid4(),
|
|
|
|
"Successfully started helper",
|
|
|
|
"Reading from device: /dev/hda",
|
|
|
|
"Received packet from %s" % random.choice(TEST_ADDRESSES),
|
|
|
|
"Received packet from %s" % random.choice(TEST_ADDRESSES),
|
|
|
|
"Received packet from %s" % random.choice(TEST_ADDRESSES),
|
|
|
|
]
|
|
|
|
|
2022-08-30 23:11:37 +00:00
|
|
|
|
2014-03-22 04:18:54 +00:00
|
|
|
def syslog_msgs():
|
2022-08-30 23:11:37 +00:00
|
|
|
global SYSLOG_LOG_CURR_TIME
|
2014-03-22 04:18:54 +00:00
|
|
|
while True:
|
2023-08-23 06:09:51 +00:00
|
|
|
SYSLOG_LOG_CURR_TIME += datetime.timedelta(seconds=random.randrange(1, 5))
|
2014-03-22 04:18:54 +00:00
|
|
|
yield '%s frontend3 %s: %s\n' % (
|
2022-08-30 23:11:37 +00:00
|
|
|
SYSLOG_LOG_CURR_TIME.strftime(SYSLOG_DATE_FMT),
|
2014-03-22 04:18:54 +00:00
|
|
|
random.choice(TEST_PROCS),
|
|
|
|
random.choice(TEST_MSGS),
|
2022-08-30 23:11:37 +00:00
|
|
|
)
|
|
|
|
|
2014-03-22 04:18:54 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
shutil.rmtree("/tmp/demo")
|
|
|
|
os.makedirs("/tmp/demo")
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
FILES = [
|
2015-03-11 13:22:50 +00:00
|
|
|
("/tmp/demo/access_log", access_log_msgs()),
|
|
|
|
("/tmp/demo/messages", syslog_msgs()),
|
2014-03-22 04:18:54 +00:00
|
|
|
]
|
|
|
|
|
2022-08-30 23:11:37 +00:00
|
|
|
COUNTER = 0
|
|
|
|
while COUNTER < 5000:
|
|
|
|
loop_inc = datetime.timedelta(seconds=random.weibullvariate(1, 1.5) * 500)
|
|
|
|
ACCESS_LOG_CURR_TIME += loop_inc
|
|
|
|
SYSLOG_LOG_CURR_TIME += loop_inc
|
2020-12-27 07:00:44 +00:00
|
|
|
for fname, gen in FILES:
|
2022-08-30 23:11:37 +00:00
|
|
|
for i in range(random.randrange(4, 8)):
|
|
|
|
COUNTER += 1
|
2020-12-27 07:00:44 +00:00
|
|
|
with open(fname, "a+") as fp:
|
2022-07-07 17:05:06 +00:00
|
|
|
if random.uniform(0.0, 1.0) < 0.01:
|
|
|
|
line = next(gen)
|
|
|
|
prefix = line[:50]
|
|
|
|
suffix = line[50:]
|
|
|
|
fp.write(prefix)
|
2022-08-30 23:11:37 +00:00
|
|
|
# time.sleep(random.uniform(0.5, 0.6))
|
2022-07-07 17:05:06 +00:00
|
|
|
fp.write(suffix)
|
|
|
|
else:
|
|
|
|
fp.write(next(gen))
|
|
|
|
# if random.uniform(0.0, 1.0) < 0.010:
|
2021-04-24 21:38:26 +00:00
|
|
|
# fp.truncate(0)
|
2023-06-16 04:28:20 +00:00
|
|
|
time.sleep(random.uniform(0.01, 0.02))
|
2022-08-30 23:11:37 +00:00
|
|
|
# if random.uniform(0.0, 1.0) < 0.001:
|
2021-04-24 21:38:26 +00:00
|
|
|
# os.remove(fname)
|