@cryptotaxi247 / netdata-1 / commits / 63bcffa9f

web_log plugin: reponse statuses chart added

Ilya committed Feb 13, 2017 at 21:01 UTC 63bcffa9f88f713611aa5f696882af630d393b8a
1 file changed +33 -7
python.d/web_log.chart.py
+33 -7
@@ -17,8 +17,8 @@ except ImportError:
17 priority = 60000
18 retries = 60
19
20 -ORDER = ['response_codes', 'bandwidth', 'response_time', 'requests_per_url', 'http_method', 'requests_per_ipproto',
21 - 'clients', 'clients_all']
20 +ORDER = ['response_statuses', 'response_codes', 'bandwidth', 'response_time', 'requests_per_url', 'http_method',
21 + 'requests_per_ipproto', 'clients', 'clients_all']
22 CHARTS = {
23 'response_codes': {
24 'options': [None, 'Response Codes', 'requests/s', 'responses', 'web_log.response_codes', 'stacked'],
@@ -66,6 +66,15 @@ CHARTS = {
66 'lines': [
67 ['req_ipv4', 'ipv4', 'incremental', 1, 1],
68 ['req_ipv6', 'ipv6', 'incremental', 1, 1]
69 + ]},
70 + 'response_statuses': {
71 + 'options': [None, 'Response Statuses', 'requests/s', 'responses', 'web_log.response_statuses',
72 + 'stacked'],
73 + 'lines': [
74 + ['successful_requests', 'successful', 'incremental', 1, 1],
75 + ['redirects', None, 'incremental', 1, 1],
76 + ['bad_requests', 'bad', 'incremental', 1, 1],
77 + ['server_errors', None, 'incremental', 1, 1]
78 ]}
79 }
80
@@ -90,11 +99,11 @@ class Service(LogService):
99 # sorted list of unique IPs
100 self.unique_all_time = list()
101 # if there is no new logs this dict returned to netdata
93 - self.data = {'bytes_sent': 0, 'resp_length': 0, 'resp_time_min': 0,
94 - 'resp_time_max': 0, 'resp_time_avg': 0, 'unique_cur_ipv4': 0,
95 - 'unique_cur_ipv6': 0, '2xx': 0, '5xx': 0, '3xx': 0, '4xx': 0,
96 - '1xx': 0, '0xx': 0, 'unmatched': 0, 'req_ipv4': 0, 'req_ipv6': 0,
97 - 'unique_tot_ipv4': 0, 'unique_tot_ipv6': 0}
102 + self.data = {'bytes_sent': 0, 'resp_length': 0, 'resp_time_min': 0, 'resp_time_max': 0,
103 + 'resp_time_avg': 0, 'unique_cur_ipv4': 0, 'unique_cur_ipv6': 0, '2xx': 0,
104 + '5xx': 0, '3xx': 0, '4xx': 0, '1xx': 0, '0xx': 0, 'unmatched': 0, 'req_ipv4': 0,
105 + 'req_ipv6': 0, 'unique_tot_ipv4': 0, 'unique_tot_ipv6': 0, 'successful_requests': 0,
106 + 'redirects': 0, 'bad_requests': 0, 'server_errors': 0}
107
108 def check(self):
109 if not self.log_path:
@@ -311,6 +320,8 @@ class Service(LogService):
320 # detailed response code
321 if self.detailed_response_codes:
322 self._get_data_detailed_response_codes(match_dict['code'])
323 + # response statuses
324 + self._get_data_statuses(match_dict['code'])
325 # requests per url
326 if self.url_pattern:
327 self._get_data_per_url(match_dict['url'])
@@ -337,6 +348,7 @@ class Service(LogService):
348 ip_address_counter['unique_cur_ip'] += 1
349 else:
350 self.data['unmatched'] += 1
351 +
352 # timings
353 if request_time:
354 self.data['resp_time_min'] += int(request_time[0])
@@ -384,6 +396,20 @@ class Service(LogService):
396 if not match:
397 self.data['other_url'] += 1
398
399 + def _get_data_statuses(self, code):
400 + """
401 + :param code: str: response status code. Ex.: '202', '499'
402 + :return:
403 + """
404 + if code[0] == '2' or code == '304' or code[0] == '1':
405 + self.data['successful_requests'] += 1
406 + elif code[0] == '3':
407 + self.data['redirects'] += 1
408 + elif code[0] == '4':
409 + self.data['bad_requests'] += 1
410 + elif code[0] == '5':
411 + self.data['server_errors'] += 1
412 +
413
414 def address_not_in_pool(pool, address, pool_size):
415 """