diff options
author | liu lei <leolovenet@gmail.com> | 2016-10-19 14:24:52 +0800 |
---|---|---|
committer | liu lei <leolovenet@gmail.com> | 2016-10-19 14:24:52 +0800 |
commit | c335489138f329e4dbcda92b0957b45c201d1b29 (patch) | |
tree | c05594b189f1fc66b61b7af04c85236282437d62 /python.d | |
parent | c9e318603b7cbfa65203d38431f43c5375f0118c (diff) |
1. changed arguments from decode() in base.py to support versions of Python 2.6
2. added pass parameters to redis for AUTH command
3. optimized nginx.chart.py and phpfpm.chart.py submenu name
4. optimized phpfpm.chart.py average display
Diffstat (limited to 'python.d')
-rw-r--r-- | python.d/nginx.chart.py | 8 | ||||
-rw-r--r--[-rwxr-xr-x] | python.d/phpfpm.chart.py | 31 | ||||
-rw-r--r-- | python.d/python_modules/base.py | 4 | ||||
-rw-r--r-- | python.d/redis.chart.py | 13 |
4 files changed, 41 insertions, 15 deletions
diff --git a/python.d/nginx.chart.py b/python.d/nginx.chart.py index ff8bfede84..de3da7c142 100644 --- a/python.d/nginx.chart.py +++ b/python.d/nginx.chart.py @@ -22,24 +22,24 @@ ORDER = ['connections', 'requests', 'connection_status', 'connect_rate'] CHARTS = { 'connections': { - 'options': [None, 'nginx Active Connections', 'connections', 'nginx', 'nginx.connections', 'line'], + 'options': [None, 'nginx Active Connections', 'connections', 'Active Connections', 'nginx.connections', 'line'], 'lines': [ ["active"] ]}, 'requests': { - 'options': [None, 'nginx Requests', 'requests/s', 'nginx', 'nginx.requests', 'line'], + 'options': [None, 'nginx Requests', 'requests/s', 'Requests', 'nginx.requests', 'line'], 'lines': [ ["requests", None, 'incremental'] ]}, 'connection_status': { - 'options': [None, 'nginx Active Connections by Status', 'connections', 'nginx', 'nginx.connection_status', 'line'], + 'options': [None, 'nginx Active Connections by Status', 'connections', 'Active Connection Status', 'nginx.connection_status', 'line'], 'lines': [ ["reading"], ["writing"], ["waiting", "idle"] ]}, 'connect_rate': { - 'options': [None, 'nginx Connections Rate', 'connections/s', 'nginx', 'nginx.connect_rate', 'line'], + 'options': [None, 'nginx Connections Rate', 'connections/s', 'Connections Rate', 'nginx.connect_rate', 'line'], 'lines': [ ["accepts", "accepted", "incremental"], ["handled", None, "incremental"] diff --git a/python.d/phpfpm.chart.py b/python.d/phpfpm.chart.py index d4168cc115..e2a5355b0f 100755..100644 --- a/python.d/phpfpm.chart.py +++ b/python.d/phpfpm.chart.py @@ -23,37 +23,37 @@ ORDER = ['connections', 'requests', 'performance', 'request_duration', 'request_ CHARTS = { 'connections': { - 'options': [None, 'PHP-FPM Active Connections', 'connections', 'phpfpm', 'phpfpm.connections', 'line'], + 'options': [None, 'PHP-FPM Active Connections', 'connections', 'Active Connections', 'phpfpm.connections', 'line'], 'lines': [ ["active"], ["maxActive", 'max active'], ["idle"] ]}, 'requests': { - 'options': [None, 'PHP-FPM Requests', 'requests/s', 'phpfpm', 'phpfpm.requests', 'line'], + 'options': [None, 'PHP-FPM Requests', 'requests/s', 'Requests', 'phpfpm.requests', 'line'], 'lines': [ ["requests", None, "incremental"] ]}, 'performance': { - 'options': [None, 'PHP-FPM Performance', 'status', 'phpfpm', 'phpfpm.performance', 'line'], + 'options': [None, 'PHP-FPM Performance', 'status', 'Performance', 'phpfpm.performance', 'line'], 'lines': [ ["reached", 'max children reached'], ["slow", 'slow requests'] ]}, 'request_duration': { - 'options': [None, 'PHP-FPM Request Duration', 'milliseconds', 'phpfpm', 'phpfpm.request_duration', 'line'], + 'options': [None, 'PHP-FPM Request Duration', 'milliseconds', 'Request Duration', 'phpfpm.request_duration', 'line'], 'lines': [ ["maxReqDur", 'max request duration'], ["avgReqDur", 'average request duration'] ]}, 'request_cpu': { - 'options': [None, 'PHP-FPM Request CPU', 'percent', 'phpfpm', 'phpfpm.request_cpu', 'line'], + 'options': [None, 'PHP-FPM Request CPU', 'percent', 'Request CPU', 'phpfpm.request_cpu', 'line'], 'lines': [ ["maxReqCPU", 'max request cpu'], ["avgReqCPU", 'average request cpu'] ]}, 'request_mem': { - 'options': [None, 'PHP-FPM Request Memory', 'kilobytes', 'phpfpm', 'phpfpm.request_mem', 'line'], + 'options': [None, 'PHP-FPM Request Memory', 'kilobytes', 'Request Memory', 'phpfpm.request_mem', 'line'], 'lines': [ ["maxReqMem", 'max request memory'], ["avgReqMem", 'average request memory'] @@ -93,9 +93,14 @@ class Service(UrlService): raw_json = json.loads(raw) except ValueError: return None - data = {self.assignment[k]: v for k, v in raw_json.items() if k in self.assignment} + data = {} + for k,v in raw_json.items(): + if k in self.assignment: + data[self.assignment[k]] = v + if '&full' in self.url or '?full' in self.url: c = 0 + sum_val = {} for proc in raw_json['processes']: if proc['state'] != 'Idle': continue @@ -108,9 +113,14 @@ class Service(UrlService): d = d/1024 if 'max' + v not in data or data['max' + v] < d: data['max' + v] = d - if 'avg' + v not in data: + if 'avg' + v not in sum_val: + sum_val['avg' + v] = 0 data['avg' + v] = 0 - data['avg' + v] = (data['avg' + v] + d) / c + sum_val['avg' + v] += d + if len(sum_val): + for k, v in sum_val.items(): + data[k] = v/c + if len(data) == 0: return None return data @@ -127,3 +137,6 @@ class Service(UrlService): if len(data) == 0: return None return data + + def check(self): + return UrlService.check(self) diff --git a/python.d/python_modules/base.py b/python.d/python_modules/base.py index 70c586f8e4..aecba8ea18 100644 --- a/python.d/python_modules/base.py +++ b/python.d/python_modules/base.py @@ -458,7 +458,7 @@ class UrlService(SimpleService): return None try: - raw = f.read().decode('utf-8') + raw = f.read().decode('utf-8', 'ignore') except Exception as e: self.error(str(e)) finally: @@ -608,7 +608,7 @@ class SocketService(SimpleService): buf = self._sock.recv(4096) if len(buf) == 0 or buf is None: # handle server disconnect break - data += buf.decode(errors='ignore') + data += buf.decode('utf-8', 'ignore') if self._check_raw_data(data): break else: diff --git a/python.d/redis.chart.py b/python.d/redis.chart.py index 218401e127..cb64a33bb7 100644 --- a/python.d/redis.chart.py +++ b/python.d/redis.chart.py @@ -68,6 +68,9 @@ class Service(SocketService): self.definitions = CHARTS self._keep_alive = True self.chart_name = "" + self.passwd = None + if 'pass' in configuration: + self.passwd = configuration['pass'] def _get_data(self): """ @@ -75,6 +78,14 @@ class Service(SocketService): :return: dict """ try: + if self.passwd: + info_request = self.request + self.request = "AUTH " + self.passwd + "\r\n" + raw = self._get_raw_data().strip() + if raw != "+OK": + self.error("invalid password") + return None + self.request = info_request raw = self._get_raw_data().split("\n") except AttributeError: self.error("no data received") @@ -112,6 +123,8 @@ class Service(SocketService): length = len(data) supposed = data.split('\n')[0][1:] offset = len(supposed) + 4 # 1 dollar sing, 1 new line character + 1 ending sequence '\r\n' + if (not supposed.isdigit()) : + return True supposed = int(supposed) if length - offset >= supposed: return True |