Skip to content

Commit c6aaf3a

Browse files
committed
增加响应时间阈值,超过阈值则在报告中标红
1 parent 28622ad commit c6aaf3a

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

bin/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, config_file):
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'))
3636
self.cost_time_percentile_flag = int(all_config.get('report', 'cost_time_percentile_flag'))
37+
self.cost_time_threshold = all_config.get('report', 'cost_time_threshold')
3738

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

bin/report.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def generate_web_log_parser_report(data):
1313
if config.goaccess_flag:
14-
data.setdefault('goaccess_file', data.get('source_file')+'_GoAccess.html')
14+
data.setdefault('goaccess_file', data.get('source_file') + '_GoAccess.html')
1515
data.setdefault('goaccess_title', u'查看GoAccess生成报告')
1616
else:
1717
data.setdefault('goaccess_file', '#')
@@ -22,7 +22,7 @@ def generate_web_log_parser_report(data):
2222
seconds_pv = sorted(list(data.get('second_hits')))
2323

2424
html = report_template.render(data=data,
25-
web_log_urls_file=data.get('source_file')+'_urls.html',
25+
web_log_urls_file=data.get('source_file') + '_urls.html',
2626
second_line_flag=config.second_line_flag,
2727
hours_pv=hours_pv,
2828
minutes_pv=minutes_pv,
@@ -31,20 +31,19 @@ def generate_web_log_parser_report(data):
3131
cost_time_range_percentile=data.get('cost_time_range_percentile'),
3232
cost_time_list=data.get('cost_time_list'),
3333
cost_time_flag=data.get('cost_time_flag'),
34-
cost_time_percentile_flag=data.get('cost_time_percentile_flag')
35-
)
34+
cost_time_percentile_flag=data.get('cost_time_percentile_flag'),
35+
cost_time_threshold=data.get('cost_time_threshold'))
3636

37-
html_file = '../result/report/'+data.get('source_file')+'.html'
37+
html_file = '../result/report/' + data.get('source_file') + '.html'
3838
with open(html_file, 'w') as f:
3939
f.write(html.encode('utf-8'))
4040

4141

4242
def generate_web_log_parser_urls(data):
43-
4443
html = url_template.render(data=data,
4544
url_datas=sorted(data.get('urls')))
4645

47-
html_file = '../result/urls/'+data.get('source_file')+'_urls.html'
46+
html_file = '../result/urls/' + data.get('source_file') + '_urls.html'
4847
with open(html_file, 'w') as f:
4948
f.write(html.encode('utf-8'))
5049

@@ -54,4 +53,3 @@ def update_index_html():
5453

5554
with open('../result/index.html', 'w') as f:
5655
f.write(html.encode('utf-8'))
57-

bin/start.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ def parse_log_file(target_file, log_format):
260260
'source_file': target_file, 'hours_hits': hours_counter, 'minutes_hits': minutes_counter,
261261
'second_hits': times_counter, 'cost_time_list': cost_time_list, 'cost_time_flag': cost_time_flag,
262262
'cost_time_range_percentile': cost_time_range_percentile, 'method_counts': method_counts,
263-
'cost_time_percentile_flag': cost_time_percentile_flag}
263+
'cost_time_percentile_flag': cost_time_percentile_flag,
264+
'cost_time_threshold': config.cost_time_threshold}
264265
generate_web_log_parser_report(total_data)
265266

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

bin/templates/report.html

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,35 @@ <h1 align="center"><a href="https://github.com/JeffXue/web-log-parser" target="g
115115
{% endif %}
116116

117117
{% for url_data in data['url_data_list'] %}
118-
<tr>
119-
<td colspan="6">
120-
<strong>{{ url_data.url.split()[1]|replace("&amp;", "&")|wordwrap(width=70, break_long_words=True, wrapstring="<br/>")|safe }}</strong>
121-
</td>
122-
<td><strong>{{ url_data.pv }}</strong></td>
123-
<td><strong>{{ url_data.ratio }}%</strong></td>
124-
<td><strong>{{ url_data.peak }}</strong></td>
125-
<td><strong>{{ url_data.url.split()[0].replace('"', '') }}</strong></td>
126-
<td><strong>{{ url_data.url.split()[2].replace('"', '') }}</strong></td>
127-
{% if url_data.cost %}
118+
{% if url_data.cost %}
119+
{% if url_data.cost_time['avg'] >= cost_time_threshold %}
120+
<tr style="color: red">
121+
{% else %}
122+
<tr>
123+
{% endif %}
124+
<td colspan="6"><strong>{{ url_data.url.split()[1]|replace("&amp;", "&")|wordwrap(width=70, break_long_words=True, wrapstring="<br/>")|safe }}</strong></td>
125+
<td><strong>{{ url_data.pv }}</strong></td>
126+
<td><strong>{{ url_data.ratio }}%</strong></td>
127+
<td><strong>{{ url_data.peak }}</strong></td>
128+
<td><strong>{{ url_data.url.split()[0].replace('"', '') }}</strong></td>
129+
<td><strong>{{ url_data.url.split()[2].replace('"', '') }}</strong></td>
128130
<td><strong>{{ url_data.cost_time['avg'] }}</strong></td>
129131
<td><strong>{{ url_data.cost_time['p9'] }}</strong></td>
130132
<td><strong>{{ url_data.cost_time['p5'] }}</strong></td>
131133
<td><strong>{{ url_data.cost_time['variance'] }}</strong></td>
132-
{% endif %}
133-
</tr>
134+
</tr>
135+
{% else %}
136+
<tr>
137+
<td colspan="6">
138+
<strong>{{ url_data.url.split()[1]|replace("&amp;", "&")|wordwrap(width=70, break_long_words=True, wrapstring="<br/>")|safe }}</strong>
139+
</td>
140+
<td><strong>{{ url_data.pv }}</strong></td>
141+
<td><strong>{{ url_data.ratio }}%</strong></td>
142+
<td><strong>{{ url_data.peak }}</strong></td>
143+
<td><strong>{{ url_data.url.split()[0].replace('"', '') }}</strong></td>
144+
<td><strong>{{ url_data.url.split()[2].replace('"', '') }}</strong></td>
145+
</tr>
146+
{% endif %}
134147
{% endfor %}
135148

136149
</table>
@@ -534,7 +547,8 @@ <h1 align="center"><a href="https://github.com/JeffXue/web-log-parser" target="g
534547
}
535548
}
536549
},
537-
data: [{% for cost_time in cost_time_list %}[new Date('{{ cost_time['time'] }}'), {{ cost_time['cost_time'] }}],{% endfor %}],
550+
data: [{% for cost_time in cost_time_list %}[
551+
new Date('{{ cost_time['time'] }}'), {{ cost_time['cost_time'] }}],{% endfor %}],
538552
}
539553
]
540554
};

conf/config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static-file=css,CSS,dae,DAE,eot,EOT,gif,GIF,ico,ICO,jpeg,JPEG,jpg,JPG,js,JS,map,
1515
second_line_flag=0
1616
cost_time_percentile_flag=1
1717
cost_time_flag=0
18+
cost_time_threshold=0.200
1819
1920
[goaccess]
2021
goaccess_flag=0

0 commit comments

Comments
 (0)