1 # -*- coding: utf-8 -*-
2 # Description: nginx log netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
5 from base import LogService
15 'options': [None, 'nginx status codes', 'requests/s', 'requests', 'nginx_log.codes', 'stacked'],
17 ["2xx", None, "incremental"],
18 ["5xx", None, "incremental"],
19 ["3xx", None, "incremental"],
20 ["4xx", None, "incremental"],
21 ["1xx", None, "incremental"],
22 ["other", None, "incremental"]
27 class Service(LogService):
28 def __init__(self, configuration=None, name=None):
29 LogService.__init__(self, configuration=configuration, name=name)
30 if len(self.log_path) == 0:
31 self.log_path = "/var/log/nginx/access.log"
33 self.definitions = CHARTS
34 pattern = r'" ([0-9]{3}) ?'
35 #pattern = r'(?:" )([0-9][0-9][0-9]) ?'
36 self.regex = re.compile(pattern)
53 raw = self._get_raw_data()
58 except (ValueError, AttributeError):
63 code = regex.search(line)
65 beginning = code.group(1)[0]
66 except AttributeError:
71 elif beginning == '3':
73 elif beginning == '4':
75 elif beginning == '5':
77 elif beginning == '1':
80 self.data["other"] += 1