@cryptotaxi247 / netdata-1 / commits / c33548913

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

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

liu lei committed Oct 19, 2016 at 14:24 UTC c335489138f329e4dbcda92b0957b45c201d1b29
5 files changed +49 -15
conf.d/python.d/redis.conf
+8
@@ -62,6 +62,8 @@
62 # host: 'IP or HOSTNAME' # the host to connect to
63 # port: PORT # the port to connect to
64 #
65 +# and
66 +# pass: 'password' # the redis password to use for AUTH command
67 #
68
69 # ----------------------------------------------------------------------
@@ -71,27 +73,33 @@
73 socket1:
74 name : 'local'
75 socket : '/tmp/redis.sock'
76 + # pass : ''
77
78 socket2:
79 name : 'local'
80 socket : '/var/run/redis/redis.sock'
81 + # pass : ''
82
83 socket3:
84 name : 'local'
85 socket : '/var/lib/redis/redis.sock'
86 + # pass : ''
87
88 localhost:
89 name : 'local'
90 host : 'localhost'
91 port : 6379
92 + # pass : ''
93
94 localipv4:
95 name : 'local'
96 host : '127.0.0.1'
97 port : 6379
98 + # pass : ''
99
100 localipv6:
101 name : 'local'
102 host : '::1'
103 port : 6379
104 + # pass : ''
105
python.d/nginx.chart.py
+4 -4
@@ -22,24 +22,24 @@ ORDER = ['connections', 'requests', 'connection_status', 'connect_rate']
22
23 CHARTS = {
24 'connections': {
25 - 'options': [None, 'nginx Active Connections', 'connections', 'nginx', 'nginx.connections', 'line'],
25 + 'options': [None, 'nginx Active Connections', 'connections', 'Active Connections', 'nginx.connections', 'line'],
26 'lines': [
27 ["active"]
28 ]},
29 'requests': {
30 - 'options': [None, 'nginx Requests', 'requests/s', 'nginx', 'nginx.requests', 'line'],
30 + 'options': [None, 'nginx Requests', 'requests/s', 'Requests', 'nginx.requests', 'line'],
31 'lines': [
32 ["requests", None, 'incremental']
33 ]},
34 'connection_status': {
35 - 'options': [None, 'nginx Active Connections by Status', 'connections', 'nginx', 'nginx.connection_status', 'line'],
35 + 'options': [None, 'nginx Active Connections by Status', 'connections', 'Active Connection Status', 'nginx.connection_status', 'line'],
36 'lines': [
37 ["reading"],
38 ["writing"],
39 ["waiting", "idle"]
40 ]},
41 'connect_rate': {
42 - 'options': [None, 'nginx Connections Rate', 'connections/s', 'nginx', 'nginx.connect_rate', 'line'],
42 + 'options': [None, 'nginx Connections Rate', 'connections/s', 'Connections Rate', 'nginx.connect_rate', 'line'],
43 'lines': [
44 ["accepts", "accepted", "incremental"],
45 ["handled", None, "incremental"]
python.d/phpfpm.chart.py
+22 -9
@@ -23,37 +23,37 @@ ORDER = ['connections', 'requests', 'performance', 'request_duration', 'request_
23
24 CHARTS = {
25 'connections': {
26 - 'options': [None, 'PHP-FPM Active Connections', 'connections', 'phpfpm', 'phpfpm.connections', 'line'],
26 + 'options': [None, 'PHP-FPM Active Connections', 'connections', 'Active Connections', 'phpfpm.connections', 'line'],
27 'lines': [
28 ["active"],
29 ["maxActive", 'max active'],
30 ["idle"]
31 ]},
32 'requests': {
33 - 'options': [None, 'PHP-FPM Requests', 'requests/s', 'phpfpm', 'phpfpm.requests', 'line'],
33 + 'options': [None, 'PHP-FPM Requests', 'requests/s', 'Requests', 'phpfpm.requests', 'line'],
34 'lines': [
35 ["requests", None, "incremental"]
36 ]},
37 'performance': {
38 - 'options': [None, 'PHP-FPM Performance', 'status', 'phpfpm', 'phpfpm.performance', 'line'],
38 + 'options': [None, 'PHP-FPM Performance', 'status', 'Performance', 'phpfpm.performance', 'line'],
39 'lines': [
40 ["reached", 'max children reached'],
41 ["slow", 'slow requests']
42 ]},
43 'request_duration': {
44 - 'options': [None, 'PHP-FPM Request Duration', 'milliseconds', 'phpfpm', 'phpfpm.request_duration', 'line'],
44 + 'options': [None, 'PHP-FPM Request Duration', 'milliseconds', 'Request Duration', 'phpfpm.request_duration', 'line'],
45 'lines': [
46 ["maxReqDur", 'max request duration'],
47 ["avgReqDur", 'average request duration']
48 ]},
49 'request_cpu': {
50 - 'options': [None, 'PHP-FPM Request CPU', 'percent', 'phpfpm', 'phpfpm.request_cpu', 'line'],
50 + 'options': [None, 'PHP-FPM Request CPU', 'percent', 'Request CPU', 'phpfpm.request_cpu', 'line'],
51 'lines': [
52 ["maxReqCPU", 'max request cpu'],
53 ["avgReqCPU", 'average request cpu']
54 ]},
55 'request_mem': {
56 - 'options': [None, 'PHP-FPM Request Memory', 'kilobytes', 'phpfpm', 'phpfpm.request_mem', 'line'],
56 + 'options': [None, 'PHP-FPM Request Memory', 'kilobytes', 'Request Memory', 'phpfpm.request_mem', 'line'],
57 'lines': [
58 ["maxReqMem", 'max request memory'],
59 ["avgReqMem", 'average request memory']
@@ -93,9 +93,14 @@ class Service(UrlService):
93 raw_json = json.loads(raw)
94 except ValueError:
95 return None
96 - data = {self.assignment[k]: v for k, v in raw_json.items() if k in self.assignment}
96 + data = {}
97 + for k,v in raw_json.items():
98 + if k in self.assignment:
99 + data[self.assignment[k]] = v
100 +
101 if '&full' in self.url or '?full' in self.url:
102 c = 0
103 + sum_val = {}
104 for proc in raw_json['processes']:
105 if proc['state'] != 'Idle':
106 continue
@@ -108,9 +113,14 @@ class Service(UrlService):
113 d = d/1024
114 if 'max' + v not in data or data['max' + v] < d:
115 data['max' + v] = d
111 - if 'avg' + v not in data:
116 + if 'avg' + v not in sum_val:
117 + sum_val['avg' + v] = 0
118 data['avg' + v] = 0
113 - data['avg' + v] = (data['avg' + v] + d) / c
119 + sum_val['avg' + v] += d
120 + if len(sum_val):
121 + for k, v in sum_val.items():
122 + data[k] = v/c
123 +
124 if len(data) == 0:
125 return None
126 return data
@@ -127,3 +137,6 @@ class Service(UrlService):
137 if len(data) == 0:
138 return None
139 return data
140 +
141 + def check(self):
142 + return UrlService.check(self)
python.d/python_modules/base.py
+2 -2
@@ -458,7 +458,7 @@ class UrlService(SimpleService):
458 return None
459
460 try:
461 - raw = f.read().decode('utf-8')
461 + raw = f.read().decode('utf-8', 'ignore')
462 except Exception as e:
463 self.error(str(e))
464 finally:
@@ -608,7 +608,7 @@ class SocketService(SimpleService):
608 buf = self._sock.recv(4096)
609 if len(buf) == 0 or buf is None: # handle server disconnect
610 break
611 - data += buf.decode(errors='ignore')
611 + data += buf.decode('utf-8', 'ignore')
612 if self._check_raw_data(data):
613 break
614 else:
python.d/redis.chart.py
+13
@@ -68,6 +68,9 @@ class Service(SocketService):
68 self.definitions = CHARTS
69 self._keep_alive = True
70 self.chart_name = ""
71 + self.passwd = None
72 + if 'pass' in configuration:
73 + self.passwd = configuration['pass']
74
75 def _get_data(self):
76 """
@@ -75,6 +78,14 @@ class Service(SocketService):
78 :return: dict
79 """
80 try:
81 + if self.passwd:
82 + info_request = self.request
83 + self.request = "AUTH " + self.passwd + "\r\n"
84 + raw = self._get_raw_data().strip()
85 + if raw != "+OK":
86 + self.error("invalid password")
87 + return None
88 + self.request = info_request
89 raw = self._get_raw_data().split("\n")
90 except AttributeError:
91 self.error("no data received")
@@ -112,6 +123,8 @@ class Service(SocketService):
123 length = len(data)
124 supposed = data.split('\n')[0][1:]
125 offset = len(supposed) + 4 # 1 dollar sing, 1 new line character + 1 ending sequence '\r\n'
126 + if (not supposed.isdigit()) :
127 + return True
128 supposed = int(supposed)
129 if length - offset >= supposed:
130 return True