]> arthur.barton.de Git - netdata.git/blobdiff - python.d/haproxy.chart.py
elasticsearch_plugin: code optimization
[netdata.git] / python.d / haproxy.chart.py
index 54070ec2848b3b62a4c7bc3acf5de68afe735319..2fb97d755bab93e5132e66d92a9fa4361202f770 100644 (file)
@@ -10,42 +10,46 @@ priority = 60000
 retries = 60
 
 # charts order (can be overridden if you want less charts, or different order)
-ORDER = ['fbin', 'fbout', 'fscur', 'fqcur', 'bbin', 'bbout', 'bscur', 'bqcur', 'health_down']
+ORDER = ['fbin', 'fbout', 'fscur', 'fqcur', 'bbin', 'bbout', 'bscur', 'bqcur', 'health_sdown', 'health_bdown']
 CHARTS = {
     'fbin': {
-        'options': [None, "Kilobytes in", "kilobytes in/s", 'Frontend', 'f.bin', 'line'],
+        'options': [None, "Kilobytes in", "kilobytes in/s", 'Frontend', 'haproxy_f.bin', 'line'],
         'lines': [
         ]},
     'fbout': {
-        'options': [None, "Kilobytes out", "kilobytes out/s", 'Frontend', 'f.bout', 'line'],
+        'options': [None, "Kilobytes out", "kilobytes out/s", 'Frontend', 'haproxy_f.bout', 'line'],
         'lines': [
         ]},
     'fscur': {
-        'options': [None, "Sessions active", "sessions", 'Frontend', 'f.scur', 'line'],
+        'options': [None, "Sessions active", "sessions", 'Frontend', 'haproxy_f.scur', 'line'],
         'lines': [
         ]},
     'fqcur': {
-        'options': [None, "Session in queue", "sessions", 'Frontend', 'f.qcur', 'line'],
+        'options': [None, "Session in queue", "sessions", 'Frontend', 'haproxy_f.qcur', 'line'],
         'lines': [
         ]},
     'bbin': {
-        'options': [None, "Kilobytes in", "kilobytes in/s", 'Backend', 'b.bin', 'line'],
+        'options': [None, "Kilobytes in", "kilobytes in/s", 'Backend', 'haproxy_b.bin', 'line'],
         'lines': [
         ]},
     'bbout': {
-        'options': [None, "Kilobytes out", "kilobytes out/s", 'Backend', 'b.bout', 'line'],
+        'options': [None, "Kilobytes out", "kilobytes out/s", 'Backend', 'haproxy_b.bout', 'line'],
         'lines': [
         ]},
     'bscur': {
-        'options': [None, "Sessions active", "sessions", 'Backend', 'b.scur', 'line'],
+        'options': [None, "Sessions active", "sessions", 'Backend', 'haproxy_b.scur', 'line'],
         'lines': [
         ]},
     'bqcur': {
-        'options': [None, "Sessions in queue", "sessions", 'Backend', 'b.qcur', 'line'],
+        'options': [None, "Sessions in queue", "sessions", 'Backend', 'haproxy_b.qcur', 'line'],
         'lines': [
         ]},
-    'health_down': {
-        'options': [None, "Servers in DOWN state", "failed servers", 'Health', 'h.down', 'line'],
+    'health_sdown': {
+        'options': [None, "Number of servers in backend in DOWN state", "failed servers", 'Health', 'haproxy_hs.down', 'line'],
+        'lines': [
+        ]},
+    'health_bdown': {
+        'options': [None, "Is backend alive? 1 = DOWN", "failed backend", 'Health', 'haproxy_hb.down', 'line'],
         'lines': [
         ]}
 }
@@ -68,8 +72,8 @@ class Service(UrlService, SocketService):
         if self.configuration.get('url'):
             self.poll_method = self.poll_method[0]
             url = self.configuration.get('url')
-            if not url.endswith(';csv'):
-                self.error('Bad url(%s). Must be http://<ip.address>:<port>/<url>;csv' % url)
+            if not url.endswith(';csv;norefresh'):
+                self.error('Bad url(%s). Must be http://<ip.address>:<port>/<url>;csv;norefresh' % url)
                 return False
         elif self.configuration.get('socket'):
             self.poll_method = self.poll_method[1]
@@ -93,7 +97,8 @@ class Service(UrlService, SocketService):
             self.definitions['bbout']['lines'].append(['_'.join(['bbout', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'incremental', 1, 1024])
             self.definitions['bscur']['lines'].append(['_'.join(['bscur', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
             self.definitions['bqcur']['lines'].append(['_'.join(['bqcur', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
-            self.definitions['health_down']['lines'].append(['_'.join(['hdown', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
+            self.definitions['health_sdown']['lines'].append(['_'.join(['hsdown', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
+            self.definitions['health_bdown']['lines'].append(['_'.join(['hbdown', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
                 
     def _get_data(self):
         """
@@ -127,11 +132,20 @@ class Service(UrlService, SocketService):
                 to_netdata.update({'_'.join([_, backend['# pxname']]): int(backend[_[1:]]) if backend.get(_[1:]) else 0})
 
         for _ in range(len(back_ends)):
-            to_netdata.update({'_'.join(['hdown', back_ends[_]['# pxname']]):
+            to_netdata.update({'_'.join(['hsdown', back_ends[_]['# pxname']]):
                            len([server for server in servers if is_server_down(server, back_ends, _)])})
+            to_netdata.update({'_'.join(['hbdown', back_ends[_]['# pxname']]): 1 if is_backend_down(back_ends, _) else 0})
 
         return to_netdata
 
+    def _check_raw_data(self, data):
+        """
+        Check if all data has been gathered from socket
+        :param data: str
+        :return: boolean
+        """
+        return not bool(data)
+
 def is_backend(backend):
     try:
         return backend['svname'] == 'BACKEND' and backend['# pxname'] != 'stats'
@@ -152,6 +166,12 @@ def is_server(server):
 
 def is_server_down(server, back_ends, _):
     try:
-        return server['# pxname'] == back_ends[_]['# pxname'] and server['status'] != 'UP'
+        return server['# pxname'] == back_ends[_]['# pxname'] and server['status'] == 'DOWN'
+    except Exception:
+        return False
+
+def is_backend_down(back_ends, _):
+    try:
+        return back_ends[_]['status'] == 'DOWN'
     except Exception:
         return False