]> arthur.barton.de Git - netdata.git/commitdiff
web_log plugin: reponse statuses chart added
authorIlya <ilyamaschenko@gmail.com>
Mon, 13 Feb 2017 12:01:20 +0000 (21:01 +0900)
committerIlya <ilyamaschenko@gmail.com>
Mon, 13 Feb 2017 12:01:20 +0000 (21:01 +0900)
python.d/web_log.chart.py

index 4e77edf3903b9c1eead79db9177a9cdd32947bec..2cb1e2b60dbbb02755601e5e08a9b4ea7e842df3 100644 (file)
@@ -17,8 +17,8 @@ except ImportError:
 priority = 60000
 retries = 60
 
-ORDER = ['response_codes', 'bandwidth', 'response_time', 'requests_per_url', 'http_method', 'requests_per_ipproto',
-         'clients', 'clients_all']
+ORDER = ['response_statuses', 'response_codes', 'bandwidth', 'response_time', 'requests_per_url', 'http_method',
+         'requests_per_ipproto', 'clients', 'clients_all']
 CHARTS = {
     'response_codes': {
         'options': [None, 'Response Codes', 'requests/s', 'responses', 'web_log.response_codes', 'stacked'],
@@ -66,6 +66,15 @@ CHARTS = {
         'lines': [
             ['req_ipv4', 'ipv4', 'incremental', 1, 1],
             ['req_ipv6', 'ipv6', 'incremental', 1, 1]
+        ]},
+    'response_statuses': {
+        'options': [None, 'Response Statuses', 'requests/s', 'responses', 'web_log.response_statuses',
+                    'stacked'],
+        'lines': [
+            ['successful_requests', 'successful', 'incremental', 1, 1],
+            ['redirects', None, 'incremental', 1, 1],
+            ['bad_requests', 'bad', 'incremental', 1, 1],
+            ['server_errors', None, 'incremental', 1, 1]
         ]}
 }
 
@@ -90,11 +99,11 @@ class Service(LogService):
         # sorted list of unique IPs
         self.unique_all_time = list()
         # if there is no new logs this dict  returned to netdata
-        self.data = {'bytes_sent': 0, 'resp_length': 0, 'resp_time_min': 0,
-                     'resp_time_max': 0, 'resp_time_avg': 0, 'unique_cur_ipv4': 0,
-                     'unique_cur_ipv6': 0, '2xx': 0, '5xx': 0, '3xx': 0, '4xx': 0,
-                     '1xx': 0, '0xx': 0, 'unmatched': 0, 'req_ipv4': 0, 'req_ipv6': 0,
-                     'unique_tot_ipv4': 0, 'unique_tot_ipv6': 0}
+        self.data = {'bytes_sent': 0, 'resp_length': 0, 'resp_time_min': 0, 'resp_time_max': 0,
+                     'resp_time_avg': 0, 'unique_cur_ipv4': 0, 'unique_cur_ipv6': 0, '2xx': 0,
+                     '5xx': 0, '3xx': 0, '4xx': 0, '1xx': 0, '0xx': 0, 'unmatched': 0, 'req_ipv4': 0,
+                     'req_ipv6': 0, 'unique_tot_ipv4': 0, 'unique_tot_ipv6': 0, 'successful_requests': 0,
+                     'redirects': 0, 'bad_requests': 0, 'server_errors': 0}
 
     def check(self):
         if not self.log_path:
@@ -311,6 +320,8 @@ class Service(LogService):
                 # detailed response code
                 if self.detailed_response_codes:
                     self._get_data_detailed_response_codes(match_dict['code'])
+                # response statuses
+                self._get_data_statuses(match_dict['code'])
                 # requests per url
                 if self.url_pattern:
                     self._get_data_per_url(match_dict['url'])
@@ -337,6 +348,7 @@ class Service(LogService):
                         ip_address_counter['unique_cur_ip'] += 1
             else:
                 self.data['unmatched'] += 1
+
         # timings
         if request_time:
             self.data['resp_time_min'] += int(request_time[0])
@@ -384,6 +396,20 @@ class Service(LogService):
         if not match:
             self.data['other_url'] += 1
 
+    def _get_data_statuses(self, code):
+        """
+        :param code: str: response status code. Ex.: '202', '499'
+        :return:
+        """
+        if code[0] == '2' or code == '304' or code[0] == '1':
+            self.data['successful_requests'] += 1
+        elif code[0] == '3':
+            self.data['redirects'] += 1
+        elif code[0] == '4':
+            self.data['bad_requests'] += 1
+        elif code[0] == '5':
+            self.data['server_errors'] += 1
+
 
 def address_not_in_pool(pool, address, pool_size):
     """