web_log_plugin: requests per http version chart added
Ilya committed
Feb 26, 2017 at 20:03 UTC
924049167ee95af5f848692a752e469c9bf52088
1 file changed
+37
-7
python.d/web_log.chart.py
+37
-7
@@ -14,7 +14,7 @@ priority = 60000
14
retries = 60
15
16
ORDER = ['response_statuses', 'response_codes', 'bandwidth', 'response_time', 'requests_per_url', 'http_method',
17
- 'requests_per_ipproto', 'clients', 'clients_all']
17
+ 'http_version', 'requests_per_ipproto', 'clients', 'clients_all']
18
CHARTS = {
19
'response_codes': {
20
'options': [None, 'Response Codes', 'requests/s', 'responses', 'web_log.response_codes', 'stacked'],
@@ -57,6 +57,10 @@ CHARTS = {
57
'lines': [
58
['GET', 'GET', 'incremental', 1, 1]
59
]},
60
+ 'http_version': {
61
+ 'options': [None, 'Requests Per HTTP Version', 'requests/s', 'http versions',
62
+ 'web_log.http_version', 'stacked'],
63
+ 'lines': []},
64
'requests_per_ipproto': {
65
'options': [None, 'Requests Per IP Protocol', 'requests/s', 'ip protocols', 'web_log.requests_per_ipproto',
66
'stacked'],
@@ -234,7 +238,8 @@ class Service(LogService):
238
'method': r'[A-Z]+',
239
'bytes_sent': r'\d+|-'}
240
optional_dict = {'resp_length': r'\d+',
237
- 'resp_time': r'[\d.]+'}
241
+ 'resp_time': r'[\d.]+',
242
+ 'http_version': r'\d\.\d'}
243
244
mandatory_values = set(mandatory_dict) - set(match_dict)
245
if mandatory_values:
@@ -275,13 +280,15 @@ class Service(LogService):
280
# 5. Bytes sent 6. Response length 7. Response process time
281
acs_default = re.compile(r'(?P<address>[\da-f.:]+)'
282
r' -.*?"(?P<method>[A-Z]+)'
278
- r' (?P<url>.*?)"'
283
+ r' (?P<url>[^ ]+)'
284
+ r' [A-Z]+/(?P<http_version>\d\.\d)"'
285
r' (?P<code>[1-9]\d{2})'
286
r' (?P<bytes_sent>\d+|-)')
287
288
acs_apache_ext_insert = re.compile(r'(?P<address>[\da-f.:]+)'
289
r' -.*?"(?P<method>[A-Z]+)'
284
- r' (?P<url>.*?)"'
290
+ r' (?P<url>[^ ]+)'
291
+ r' [A-Z]+/(?P<http_version>\d\.\d)"'
292
r' (?P<code>[1-9]\d{2})'
293
r' (?P<bytes_sent>\d+|-)'
294
r' (?P<resp_length>\d+)'
@@ -289,7 +296,8 @@ class Service(LogService):
296
297
acs_apache_ext_append = re.compile(r'(?P<address>[\da-f.:]+)'
298
r' -.*?"(?P<method>[A-Z]+)'
292
- r' (?P<url>.*?)"'
299
+ r' (?P<url>[^ ]+)'
300
+ r' [A-Z]+/(?P<http_version>\d\.\d)"'
301
r' (?P<code>[1-9]\d{2})'
302
r' (?P<bytes_sent>\d+|-)'
303
r' .*?'
@@ -299,7 +307,8 @@ class Service(LogService):
307
308
acs_nginx_ext_insert = re.compile(r'(?P<address>[\da-f.:]+)'
309
r' -.*?"(?P<method>[A-Z]+)'
302
- r' (?P<url>.*?)"'
310
+ r' (?P<url>[^ ]+)'
311
+ r' [A-Z]+/(?P<http_version>\d\.\d)"'
312
r' (?P<code>[1-9]\d{2})'
313
r' (?P<bytes_sent>\d+)'
314
r' (?P<resp_length>\d+)'
@@ -307,7 +316,8 @@ class Service(LogService):
316
317
acs_nginx_ext_append = re.compile(r'(?P<address>[\da-f.:]+)'
318
r' -.*?"(?P<method>[A-Z]+)'
310
- r' (?P<url>.*?)"'
319
+ r' (?P<url>[^ ]+)'
320
+ r' [A-Z]+/(?P<http_version>\d\.\d)"'
321
r' (?P<code>[1-9]\d{2})'
322
r' (?P<bytes_sent>\d+)'
323
r' .*?'
@@ -369,6 +379,9 @@ class Service(LogService):
379
' "" "Requests Per HTTP Method" requests/s "http methods"' \
380
' web_log.http_method stacked 2 %s\n' \
381
'DIMENSION GET GET incremental\n' % (job_name, self.update_every)
382
+ self.http_version_chart = 'CHART %s.http_version' \
383
+ ' "" "Requests Per HTTP Version" requests/s "http versions"' \
384
+ ' web_log.http_version stacked 3 %s\n' % (job_name, self.update_every)
385
386
# Remove 'request_time' chart from ORDER if resp_time not in match_dict
387
if 'resp_time' not in match_dict:
@@ -448,6 +461,9 @@ class Service(LogService):
461
self._get_data_per_url(match_dict['url'])
462
# requests per http method
463
self._get_data_http_method(match_dict['method'])
464
+ # requests per http version
465
+ if 'http_version' in match_dict:
466
+ self._get_data_http_version(match_dict['http_version'])
467
# bandwidth sent
468
bytes_sent = match_dict['bytes_sent'] if '-' not in match_dict['bytes_sent'] else 0
469
self.data['bytes_sent'] += int(bytes_sent)
@@ -503,6 +519,20 @@ class Service(LogService):
519
chart_string_copy, 'http_method')
520
self.data[method] += 1
521
522
+ def _get_data_http_version(self, http_version):
523
+ """
524
+ :param http_version: str: METHOD from parsed line. Ex.: '1.1', '1.0'
525
+ :return:
526
+ Calls add_new_dimension method If the value is found for the first time
527
+ """
528
+ http_version_dim_id = http_version.replace('.', '_')
529
+ if http_version_dim_id not in self.data:
530
+ chart_string_copy = self.http_version_chart
531
+ self.http_version_chart = self.add_new_dimension(http_version_dim_id,
532
+ [http_version_dim_id, http_version, 'incremental'],
533
+ chart_string_copy, 'http_version')
534
+ self.data[http_version_dim_id] += 1
535
+
536
def _get_data_per_url(self, url):
537
"""
538
:param url: str: URL from parsed line