@cryptotaxi247 / netdata-1 / commits / 1096a3f28

web_log plugin: requests per mime type chart added for squid

Ilya committed May 31, 2017 at 19:38 UTC 1096a3f2846a393f7190b14f2e68cda3f82446a2
1 file changed +28 -18
python.d/web_log.chart.py
+28 -18
@@ -20,9 +20,9 @@ ORDER_WEB = ['response_statuses', 'response_codes', 'bandwidth', 'response_time'
20 'clients', 'clients_all']
21
22 ORDER_SQUID = ['squid_response_statuses', 'squid_response_codes', 'squid_detailed_response_codes',
23 - 'squid_method', 'squid_hier_code', 'squid_transport_methods', 'squid_transport_errors',
24 - 'squid_code', 'squid_handling_opts', 'squid_object_types', 'squid_cache_events', 'squid_bytes',
25 - 'squid_duration', 'squid_clients', 'squid_clients_all']
23 + 'squid_method', 'squid_mime_type', 'squid_hier_code', 'squid_transport_methods',
24 + 'squid_transport_errors', 'squid_code', 'squid_handling_opts', 'squid_object_types',
25 + 'squid_cache_events', 'squid_bytes', 'squid_duration', 'squid_clients', 'squid_clients_all']
26
27 CHARTS_WEB = {
28 'response_codes': {
@@ -170,6 +170,11 @@ CHARTS_SQUID = {
170 'requests/s', 'squid_requests', 'web_log.squid_method', 'stacked'],
171 'lines': [
172 ]},
173 + 'squid_mime_type': {
174 + 'options': [None, 'Requests Per MIME Type',
175 + 'requests/s', 'squid_requests', 'web_log.squid_mime_type', 'stacked'],
176 + 'lines': [
177 + ]},
178 'squid_clients': {
179 'options': [None, 'Current Poll Unique Client IPs', 'unique ips', 'squid_clients',
180 'web_log.squid_clients', 'stacked'],
@@ -215,11 +220,6 @@ NAMED_PATTERN = namedtuple('PATTERN', ['description', 'pattern'])
220
221 DET_RESP_AGGR = ['', '_1xx', '_2xx', '_3xx', '_4xx', '_5xx', '_Other']
222
218 -SQUID_DYNAMIC = dict(squid_code='squid_code',
219 - http_code='squid_detailed_response_codes',
220 - hier_code='squid_hier_code',
221 - method='squid_method')
222 -
223 SQUID_CODES = dict(TCP='squid_transport_methods', UDP='squid_transport_methods', NONE='squid_transport_methods',
224 CLIENT='squid_handling_opts', IMS='squid_handling_opts', ASYNC='squid_handling_opts',
225 SWAPFAIL='squid_handling_opts', REFRESH='squid_handling_opts', SHARED='squid_handling_opts',
@@ -398,7 +398,7 @@ class Web(Mixin):
398 codes = DET_RESP_AGGR[:1] if self.conf.get('detailed_response_aggregate', True) else DET_RESP_AGGR[1:]
399 for code in codes:
400 self.order.append('detailed_response_codes%s' % code)
401 - self.definitions['detailed_response_codes%s' % code]\
401 + self.definitions['detailed_response_codes%s' % code] \
402 = {'options': [None, 'Detailed Response Codes %s' % code[1:], 'requests/s', 'responses',
403 'web_log.detailed_response_codes%s' % code, 'stacked'],
404 'lines': []}
@@ -776,7 +776,7 @@ class Squid(Mixin):
776 r' (?P<squid_code>[A-Z_]+)/'
777 r'(?P<http_code>[0-9]+)'
778 r' (?P<bytes>[0-9]+)'
779 - r' (?P<method>[A-Z]+)'
779 + r' (?P<method>[A-Z_]+)'
780 r' (?P<url>[^ ]+)'
781 r' (?P<user>[^ ]+)'
782 r' (?P<hier_code>[A-Z_]+)/[\da-f.:-]+'
@@ -786,6 +786,16 @@ class Squid(Mixin):
786 if not match:
787 self.error('Regex not matches (%s)' % self.storage['regex'].pattern)
788 return False
789 + self.storage['dynamic'] = {'squid_code': {'chart': 'squid_code',
790 + 'func': None},
791 + 'http_code': {'chart': 'squid_detailed_response_codes',
792 + 'func': None},
793 + 'hier_code': {'chart': 'squid_hier_code',
794 + 'func': lambda v: v.replace('HIER_', '')},
795 + 'method': {'chart': 'squid_method',
796 + 'func': None},
797 + 'mime_type': {'chart': 'squid_mime_type',
798 + 'func': lambda v: v.split('/')[0]}}
799 return True
800
801 def get_data(self, raw_data=None):
@@ -822,14 +832,14 @@ class Squid(Mixin):
832 self.data['unique_' + proto] += 1
833 unique_ip.add(match['client_address'])
834
825 - for key, chart_key in SQUID_DYNAMIC.items():
826 - if match[key] not in self.data:
827 - dimension = match[key].replace('HIER_', '')
828 - self.add_new_dimension(dimension_id=match[key],
829 - chart_key=chart_key,
830 - dimension=dimension)
831 - else:
832 - self.data[match[key]] += 1
835 + for key, values in self.storage['dynamic'].items():
836 + if match[key] == '-':
837 + continue
838 + dimension_id = values['func'](match[key]) if values['func'] else match[key]
839 + if dimension_id not in self.data:
840 + self.add_new_dimension(dimension_id=dimension_id,
841 + chart_key=values['chart'])
842 + self.data[dimension_id] += 1
843 else:
844 self.data['unmatched'] += 1
845