]> arthur.barton.de Git - netdata.git/commitdiff
1. changed arguments from decode() in base.py to support versions of Python 2.6
authorliu lei <leolovenet@gmail.com>
Wed, 19 Oct 2016 06:24:52 +0000 (14:24 +0800)
committerliu lei <leolovenet@gmail.com>
Wed, 19 Oct 2016 06:24:52 +0000 (14:24 +0800)
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

conf.d/python.d/redis.conf
python.d/nginx.chart.py
python.d/phpfpm.chart.py [changed mode: 0755->0644]
python.d/python_modules/base.py
python.d/redis.chart.py

index e1ce2de2e649a8e7ba36db2eedca45e548416341..983fbfbdb3087e659d379ddba7d9c80e83415f7b 100644 (file)
@@ -62,6 +62,8 @@
 #     host: 'IP or HOSTNAME' # the host to connect to
 #     port: PORT             # the port to connect to
 #
+#  and
+#     pass: 'password'       # the redis password to use for AUTH command
 #
 
 # ----------------------------------------------------------------------
 socket1:
   name     : 'local'
   socket   : '/tmp/redis.sock'
+  # pass     : ''
 
 socket2:
   name     : 'local'
   socket   : '/var/run/redis/redis.sock'
+  # pass     : ''
 
 socket3:
   name     : 'local'
   socket   : '/var/lib/redis/redis.sock'
+  # pass     : ''
 
 localhost:
   name     : 'local'
   host     : 'localhost'
   port     : 6379
+  # pass     : ''
 
 localipv4:
   name     : 'local'
   host     : '127.0.0.1'
   port     : 6379
+  # pass     : ''
 
 localipv6:
   name     : 'local'
   host     : '::1'
   port     : 6379
+  # pass     : ''
 
index ff8bfede84328c280395883d7d4b72d67425afa7..de3da7c14285d3a909d2324fafce0f627e5f7182 100644 (file)
@@ -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"]
old mode 100755 (executable)
new mode 100644 (file)
index d4168cc..e2a5355
@@ -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)
index 70c586f8e411a276b829406cddc75cbcf8a4b7cf..aecba8ea1895cb83017342daceaec55ac7069813 100644 (file)
@@ -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:
index 218401e1276d081a052dff0322cb607984723579..cb64a33bb7c9a97e7ba783a86da2798520ea4cc0 100644 (file)
@@ -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