-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats-generator.py
93 lines (79 loc) · 3.33 KB
/
stats-generator.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
import json
import os
from docx import Document
def extract_metrics(filename):
if not os.path.isfile(filename):
print(f"Error: File '{filename}' not found.")
return None
metrics = {
'http_req_duration': {'max': 0},
'http_reqs': {'count': 0},
'http_req_failed': {'fails': 0}
}
try:
with open(filename, 'r') as f:
for line in f:
try:
data = json.loads(line.strip())
metric_type = data.get('metric')
if metric_type:
if metric_type == 'http_reqs':
# Add debug information
# print(f"Processing http_reqs: {data}")
value = data['data'].get('value', 0)
metrics['http_reqs']['count'] += value
elif metric_type == 'http_req_duration':
# Add debug information
# print(f"Processing http_req_duration: {data}")
value = data['data'].get('value', 0)
if value > metrics['http_req_duration']['max']:
metrics['http_req_duration']['max'] = value
elif metric_type == 'http_req_failed':
# Add debug information
# print(f"Processing http_req_failed: {data}")
value = data['data'].get('value', 0)
metrics['http_req_failed']['fails'] += value
except json.JSONDecodeError as e:
print(f"Error decoding JSON line: {e}")
except IOError as e:
print(f"Error reading file: {e}")
return None
return (
metrics['http_req_duration']['max'],
metrics['http_reqs']['count'],
metrics['http_req_failed']['fails']
)
# Create a new Word document
doc = Document()
doc.add_heading('Da3em Stress Test Report', 0)
# Add a summary section
doc.add_heading('Test Summary', level=1)
# Create a table for the test results
table = doc.add_table(rows=1, cols=4)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Stage'
hdr_cells[1].text = 'Max Response Time (ms)'
hdr_cells[2].text = 'Success Requests'
hdr_cells[3].text = 'Error Requests'
# Process each stage and add rows to the table
stages = [
('20 VUs', 'stage_20_vus_output.json'),
('100 VUs', 'stage_100_vus_output.json'),
('500 VUs', 'stage_500_vus_output.json'),
('1000 VUs', 'stage_1000_vus_output.json'),
('5000 VUs', 'stage_5000_vus_output.json')
]
for stage_name, file_name in stages:
metrics = extract_metrics(file_name)
if metrics:
max_response_time, successful_requests, error_requests = metrics
row_cells = table.add_row().cells
row_cells[0].text = stage_name
row_cells[1].text = str(max_response_time)
row_cells[2].text = str(successful_requests)
row_cells[3].text = str(error_requests)
# Add a section for more details if needed
doc.add_heading('Details', level=1)
doc.add_paragraph('This report includes the essential metrics from the Da3em K6 stress test for each stage of the test.')
# Save the document to a file
doc.save('egg_Stress_Test_Report_Combined.docx')