web_log plugin: response statuses chart for squid added
Ilya committed
May 30, 2017 at 11:20 UTC
65ff31026c9db50e8db9d08ecda69e6b4733a67b
1 file changed
+33
-5
python.d/web_log.chart.py
+33
-5
@@ -19,7 +19,7 @@ ORDER_WEB = ['response_statuses', 'response_codes', 'bandwidth', 'response_time'
19
'requests_per_user_defined', 'http_method', 'http_version', 'requests_per_ipproto',
20
'clients', 'clients_all']
21
22
-ORDER_SQUID = ['squid_response_codes', 'squid_code', 'http_code',
22
+ORDER_SQUID = ['response_statuses', 'response_codes', 'squid_code', 'http_code',
23
'hier_code', 'bytes', 'duration', 'method', 'clients']
24
25
CHARTS_WEB = {
@@ -125,7 +125,16 @@ CHARTS_SQUID = {
125
'lines': [
126
['bytes', 'sent', 'incremental', 1, 1024]
127
]},
128
- 'squid_response_codes': {
128
+ 'response_statuses': {
129
+ 'options': [None, 'Response Statuses', 'responses/s', 'responses', 'web_log.squid_response_statuses',
130
+ 'stacked'],
131
+ 'lines': [
132
+ ['successful_requests', 'success', 'incremental', 1, 1],
133
+ ['server_errors', 'error', 'incremental', 1, 1],
134
+ ['redirects', 'redirect', 'incremental', 1, 1],
135
+ ['bad_requests', 'bad', 'incremental', 1, 1]
136
+ ]},
137
+ 'response_codes': {
138
'options': [None, 'Response Codes', 'responses/s', 'responses', 'web_log.squid_response_codes', 'stacked'],
139
'lines': [
140
['2xx', None, 'incremental'],
@@ -711,9 +720,11 @@ class Squid(Mixin):
720
r' (?P<user>[^ ]+)'
721
r' (?P<hier_code>[A-Z_]+)/[0-9.-]+'
722
r' (?P<mime_type>[^\n]+)')
714
- self.data = {'duration_max': 0, 'duration_avg': 0, 'duration_min': 0,
715
- 'bytes': 0, '0xx': 0, '1xx': 0, '2xx': 0, '3xx': 0, '4xx': 0,
716
- '5xx': 0, 'other': 0, 'unmatched': 0, 'unique_ipv4': 0, 'unique_ipv6': 0}
723
+ self.data = {'duration_max': 0, 'duration_avg': 0, 'duration_min': 0, 'bytes': 0,
724
+ '0xx': 0, '1xx': 0, '2xx': 0, '3xx': 0, '4xx': 0, '5xx': 0,
725
+ 'other': 0, 'unmatched': 0, 'unique_ipv4': 0, 'unique_ipv6': 0,
726
+ 'successful_requests': 0, 'redirects': 0, 'bad_requests': 0, 'server_errors': 0
727
+ }
728
729
def check(self):
730
last_line = self.get_last_line()
@@ -741,6 +752,8 @@ class Squid(Mixin):
752
except KeyError:
753
self.data['other'] += 1
754
755
+ self.get_data_per_statuses(match['http_code'])
756
+
757
self.data['bytes'] += int(match['bytes'])
758
759
proto = 'ipv4' if '.' in match['client_address'] else 'ipv6'
@@ -764,6 +777,21 @@ class Squid(Mixin):
777
self.data['duration_avg'] += sum(duration) / length
778
return self.data
779
780
+ def get_data_per_statuses(self, code):
781
+ """
782
+ :param code: str: response status code. Ex.: '202', '499'
783
+ :return:
784
+ """
785
+ code_class = code[0]
786
+ if code_class == '2' or code == '304' or code_class == '1':
787
+ self.data['successful_requests'] += 1
788
+ elif code_class == '3':
789
+ self.data['redirects'] += 1
790
+ elif code_class == '5':
791
+ self.data['server_errors'] += 1
792
+ else:
793
+ self.data['bad_requests'] += 1
794
+
795
796
def address_not_in_pool(pool, address, pool_size):
797
"""