Skip to content

Commit fe3880e

Browse files
committed
在配置为不带参数分析时,支持固定的URL参数,以区分部分的请求
1 parent 92c1800 commit fe3880e

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

bin/config.py

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

1616
self.support_method = all_config.get('filter', 'support_method').split(',')
1717
self.is_with_parameters = int(all_config.get('filter', 'is_with_parameters'))
18+
self.always_parameter_keys = all_config.get('filter', 'always_parameter_keys').split(',')
1819
self.urls_most_number = int(all_config.get('filter', 'urls_most_number'))
1920
self.urls_pv_threshold = int(all_config.get('filter', 'urls_pv_threshold'))
2021
self.fixed_parameter_keys = all_config.get('filter', 'fixed_parameter_keys').split(',')

bin/start.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ def get_new_url(origin_url):
9090
return new_url
9191

9292

93+
def get_new_url_for_always_parameters(origin_url):
94+
if len(origin_url.split('?')) == 1:
95+
return origin_url
96+
97+
url_front = origin_url.split('?')[0]
98+
url_parameters = sorted(origin_url.split('?')[1].split('&'))
99+
new_url_parameters = []
100+
for parameter in url_parameters:
101+
key = parameter.split('=')[0]
102+
if key in config.always_parameter_keys:
103+
new_url_parameters.append(parameter)
104+
if new_url_parameters:
105+
new_url = url_front + '?' + '&'.join(new_url_parameters)
106+
else:
107+
new_url = origin_url
108+
return new_url
109+
110+
93111
def parse_log_file(target_file, log_format):
94112
# 用户IP
95113
hosts = []
@@ -125,7 +143,10 @@ def parse_log_file(target_file, log_format):
125143
if config.is_with_parameters:
126144
url = get_new_url(match.group(log_format.get('url_index')))
127145
else:
128-
url = match.group(log_format.get('url_index')).split('?')[0]
146+
if config.always_parameter_keys:
147+
url = get_new_url_for_always_parameters(match.group(log_format.get('url_index')))
148+
else:
149+
url = match.group(log_format.get('url_index')).split('?')[0]
129150
if is_ignore_url(url):
130151
continue
131152
if match.group(log_format.get('method_index')) not in config.support_method:
@@ -187,7 +208,10 @@ def parse_log_file(target_file, log_format):
187208
if config.is_with_parameters:
188209
url = get_new_url(match.group(log_format.get('url_index')))
189210
else:
190-
url = match.group(log_format.get('url_index')).split('?')[0]
211+
if config.always_parameter_keys:
212+
url = get_new_url_for_always_parameters(match.group(log_format.get('url_index')))
213+
else:
214+
url = match.group(log_format.get('url_index')).split('?')[0]
191215
for url_data in url_data_list:
192216
if url_data.url == ' '.join([method, url]):
193217
url_data.time.append(match.group(log_format.get('time_index')))

conf/config.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ log-pattern=(\S+)\s\S+\s(\S+)\s(\S+)\s(\d+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s
66
log-format=datetime method url status protocol business_status cost host hostname real_ip
77

88
[filter]
9+
# 支持的方法
910
support_method=POST,GET
11+
# 是否带参数进行分析(但会包括awalys_parameter_keys所指定的参数)
1012
is_with_parameters=0
13+
always_parameter_keys=action
14+
# 访问量排行最大请求数量
1115
urls_most_number=200
16+
# 访问量排行的最低PV阀值,低于该阀值的不会进入访问量排行
1217
urls_pv_threshold=1000
18+
# 固定的参数,但is_with_parameters=1时,不会替换一下key的值
1319
fixed_parameter_keys=action,submitType,reportType
20+
# 自定义的参数转换
1421
custom_parameters=t={timeStamp},v={timeStamp},_={timeStamp}
22+
# 忽略的URL
1523
ignore_urls=/slb.html,/server-status,/httpstatus.html,/server-status-dinghuo/,/server-status-dinghuo
24+
# 忽略的请求类型
1625
static-file=css,CSS,dae,DAE,eot,EOT,gif,GIF,ico,ICO,jpeg,JPEG,jpg,JPG,js,JS,map,MAP,mp3,MP3,pdf,PDF,png,PNG,svg,SVG,swf,SWF,ttf,TTF,txt,TXT,woff,WOFF
1726

1827
[report]

0 commit comments

Comments
 (0)