Skip to content

Commit 28622ad

Browse files
committed
拆分响应时间占比图与散点图标志位,默认不展示散点图
(数据量较大时,生成散点图时导致无法展示,超过100W条的数据最好不要打开散点图,后续再看如何优化)
1 parent a164299 commit 28622ad

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

bin/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, config_file):
3333

3434
self.second_line_flag = int(all_config.get('report', 'second_line_flag'))
3535
self.cost_time_flag = int(all_config.get('report', 'cost_time_flag'))
36+
self.cost_time_percentile_flag = int(all_config.get('report', 'cost_time_percentile_flag'))
3637

3738
self.goaccess_flag = int(all_config.get('goaccess', 'goaccess_flag'))
3839
self.time_format = all_config.get('goaccess', 'time-format')

bin/report.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ def generate_web_log_parser_report(data):
2929
seconds_pv=seconds_pv,
3030
method_counts=data.get('method_counts'),
3131
cost_time_range_percentile=data.get('cost_time_range_percentile'),
32-
cost_times_list=data.get('cost_times_list'),
33-
cost_times_flag=data.get('cost_times_flag')
32+
cost_time_list=data.get('cost_time_list'),
33+
cost_time_flag=data.get('cost_time_flag'),
34+
cost_time_percentile_flag=data.get('cost_time_percentile_flag')
3435
)
3536

3637
html_file = '../result/report/'+data.get('source_file')+'.html'

bin/start.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ def parse_log_file(target_file, log_format):
9898
# 请求URL
9999
urls = []
100100
# 请求响应时间
101-
cost_times_list = []
102-
if 'cost_time_index' in log_format.keys() and config.cost_time_flag:
103-
cost_times_flag = True
104-
else:
105-
cost_times_flag = False
101+
cost_time_list = []
102+
cost_time_flag = False
103+
cost_time_percentile_flag = False
104+
if 'cost_time_index' in log_format.keys():
105+
if config.cost_time_flag:
106+
cost_time_flag = True
107+
if config.cost_time_percentile_flag:
108+
cost_time_percentile_flag = True
109+
106110
# 请求方法计数器
107111
method_counts = {'post': 0, 'post_percentile': 0, 'get': 0, 'get_percentile': 0}
108112

@@ -136,8 +140,8 @@ def parse_log_file(target_file, log_format):
136140
method_counts['get'] += 1
137141
protocol = match.group(log_format.get('protocol_index'))
138142
urls.append(method+' '+url+' '+protocol)
139-
if cost_times_flag:
140-
cost_times_list.append({'time': log_time, 'cost_time': int(float(match.group(log_format.get('cost_time_index')))*1000)})
143+
if 'cost_time_index' in log_format.keys():
144+
cost_time_list.append({'time': log_time, 'cost_time': int(float(match.group(log_format.get('cost_time_index')))*1000)})
141145

142146
# 计算PV、UV、平均请求数、GET/POST占比
143147
pv = len(times)
@@ -200,7 +204,7 @@ def parse_log_file(target_file, log_format):
200204
# 统计不同响应时间范围的请求数量
201205
cost_time_range = {'r1': 0, 'r2': 0, 'r3': 0, 'r4': 0, 'r5': 0, 'r6': 0,
202206
'r7': 0, 'r8': 0, 'r9': 0, 'r10': 0, 'r11': 0}
203-
for cost_time in cost_times_list:
207+
for cost_time in cost_time_list:
204208
if cost_time['cost_time'] <= 50:
205209
cost_time_range['r1'] += 1
206210
elif 50 < cost_time['cost_time'] <= 100:
@@ -223,12 +227,11 @@ def parse_log_file(target_file, log_format):
223227
cost_time_range['r10'] += 1
224228
else:
225229
cost_time_range['r11'] += 1
226-
227230
# 计算不同响应时间范围的请求占比
228231
cost_time_range_percentile = {'r1p': 0, 'r2p': 0, 'r3p': 0, 'r4p': 0, 'r5p': 0, 'r6p': 0,
229232
'r7p': 0, 'r8p': 0, 'r9p': 0, 'r10p': 0, 'r11p': 0}
230-
if cost_times_list:
231-
total_cost_time_pv = float(len(cost_times_list))
233+
if cost_time_list:
234+
total_cost_time_pv = float(len(cost_time_list))
232235
if cost_time_range['r1']:
233236
cost_time_range_percentile['r1p'] = '%0.3f' % float(cost_time_range['r1']*100/total_cost_time_pv)
234237
if cost_time_range['r2']:
@@ -255,8 +258,9 @@ def parse_log_file(target_file, log_format):
255258
total_data = {'pv': pv, 'uv': uv, 'response_avg': response_avg, 'response_peak': response_peak,
256259
'response_peak_time': response_peak_time, 'url_data_list': url_data_list,
257260
'source_file': target_file, 'hours_hits': hours_counter, 'minutes_hits': minutes_counter,
258-
'second_hits': times_counter, 'cost_times_list': cost_times_list, 'cost_times_flag': cost_times_flag,
259-
'cost_time_range_percentile': cost_time_range_percentile, 'method_counts': method_counts}
261+
'second_hits': times_counter, 'cost_time_list': cost_time_list, 'cost_time_flag': cost_time_flag,
262+
'cost_time_range_percentile': cost_time_range_percentile, 'method_counts': method_counts,
263+
'cost_time_percentile_flag': cost_time_percentile_flag}
260264
generate_web_log_parser_report(total_data)
261265

262266
total_data = {'source_file': target_file, 'urls': urls_counter}

bin/templates/report.html

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,23 @@ <h1 align="center"><a href="https://github.com/JeffXue/web-log-parser" target="g
5959
{% endif %}
6060
</table>
6161

62-
{% if cost_times_flag %}
62+
{% if cost_time_percentile_flag %}
6363
<br>
6464
<table class="bordered">
6565
<tr>
6666
<td>
67-
<div id="costPChart" style="height:400px; width: 670px;"></div>
67+
<div id="costPChart" style="height:400px"></div>
6868
</td>
69+
</tr>
70+
</table>
71+
{% endif %}
72+
73+
{% if cost_time_flag %}
74+
<br>
75+
<table class="bordered">
76+
<tr>
6977
<td>
70-
<div id="costChart" style="height:400px; width: 670px;"></div>
78+
<div id="costChart" style="height:400px"></div>
7179
</td>
7280
</tr>
7381
</table>
@@ -204,6 +212,7 @@ <h1 align="center"><a href="https://github.com/JeffXue/web-log-parser" target="g
204212
}
205213
]
206214
};
215+
hoursChart.setOption(hoursOption);
207216

208217
var minuteChart = ec.init(document.getElementById('minutesChart'), theme);
209218

@@ -263,6 +272,7 @@ <h1 align="center"><a href="https://github.com/JeffXue/web-log-parser" target="g
263272
}
264273
]
265274
};
275+
minuteChart.setOption(minuteOption);
266276

267277
{% if second_line_flag %}
268278
var secondChart = ec.init(document.getElementById('secondChart'), theme);
@@ -375,10 +385,11 @@ <h1 align="center"><a href="https://github.com/JeffXue/web-log-parser" target="g
375385
}
376386
]
377387
};
388+
methodChart.setOption(methodOption);
378389

379-
{% if cost_times_flag %}
390+
391+
{% if cost_time_percentile_flag %}
380392
var costPChart = ec.init(document.getElementById('costPChart'), theme);
381-
var costChart = ec.init(document.getElementById('costChart'), theme);
382393

383394
var costPOption = {
384395
title: {
@@ -446,7 +457,11 @@ <h1 align="center"><a href="https://github.com/JeffXue/web-log-parser" target="g
446457
}
447458
]
448459
};
460+
costPChart.setOption(costPOption);
461+
{% endif %}
449462

463+
{% if cost_time_flag %}
464+
var costChart = ec.init(document.getElementById('costChart'), theme);
450465
var costOption = {
451466
title: {
452467
text: '响应时间分布图(时间维度)',
@@ -519,18 +534,13 @@ <h1 align="center"><a href="https://github.com/JeffXue/web-log-parser" target="g
519534
}
520535
}
521536
},
522-
data: [{% for cost_time in cost_times_list %}[new Date('{{ cost_time['time'] }}'), {{ cost_time['cost_time'] }}],{% endfor %}],
537+
data: [{% for cost_time in cost_time_list %}[new Date('{{ cost_time['time'] }}'), {{ cost_time['cost_time'] }}],{% endfor %}],
523538
}
524539
]
525540
};
526-
527-
costPChart.setOption(costPOption);
528541
costChart.setOption(costOption);
529542
{% endif %}
530543

531-
hoursChart.setOption(hoursOption);
532-
minuteChart.setOption(minuteOption);
533-
methodChart.setOption(methodOption);
534544
}
535545
);
536546
</script>

conf/config.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ static-file=css,CSS,dae,DAE,eot,EOT,gif,GIF,ico,ICO,jpeg,JPEG,jpg,JPG,js,JS,map,
1313
1414
[report]
1515
second_line_flag=0
16-
cost_time_flag=1
16+
cost_time_percentile_flag=1
17+
cost_time_flag=0
1718
1819
[goaccess]
1920
goaccess_flag=0

0 commit comments

Comments
 (0)