]> arthur.barton.de Git - netdata.git/blobdiff - python.d/nginx.chart.py
Merge pull request #643 from paulfantom/master
[netdata.git] / python.d / nginx.chart.py
index 6675a69d407bddf0d97204a037b776418289704e..c50d0b72c675990e16c054e9980ac4f0111f71bd 100644 (file)
@@ -22,57 +22,52 @@ ORDER = ['connections', 'requests', 'connection_status', 'connect_rate']
 
 CHARTS = {
     'connections': {
-        'options': "'' 'nginx Active Connections' 'connections' nginx nginx.connections line",
+        'options': [None, 'nginx Active Connections', 'connections', 'nginx', 'nginx.connections', 'line'],
         'lines': [
-            {"name": "active",
-             "options": "'' absolute 1 1"},
+            ["active"]
         ]},
     'requests': {
-        'options': "'' 'nginx Requests' 'requests/s' nginx nginx.requests line",
+        'options': [None, 'nginx Requests', 'requests/s', 'nginx', 'nginx.requests', 'line'],
         'lines': [
-            {"name": "requests",
-             "options": "'' incremental 1 1"}
+            ["requests", None, 'incremental']
         ]},
     'connection_status': {
-        'options': "'' 'nginx Active Connections by Status' 'connections' nginx nginx.connection.status line",
+        'options': [None, 'nginx Active Connections by Status', 'connections', 'nginx', 'nginx.connection.status', 'line'],
         'lines': [
-            {"name": "reading",
-             "options": "'' absolute 1 1"},
-            {"name": "writing",
-             "options": "'' absolute 1 1"},
-            {"name": "waiting",
-             "options": "'' absolute 1 1"}
+            ["reading"],
+            ["writing"],
+            ["waiting", "idle"]
         ]},
     'connect_rate': {
-        'options': "'' 'nginx Connections Rate' 'connections/s' nginx nginx.performance line",
+        'options': [None, 'nginx Connections Rate', 'connections/s', 'nginx', 'nginx.performance', 'line'],
         'lines': [
-            {"name": "accepts",
-             "options": "'accepted' incremental 1 1"},
-            {"name": "handled",
-             "options": "'' incremental 1 1"}
+            ["accepts", "accepted", "incremental"],
+            ["handled", None, "incremental"]
         ]}
 }
 
 
 class Service(UrlService):
-    # url = "http://localhost/stub_status"
-    url = "http://toothless.dragon/stub_status"
-    order = ORDER
-    charts = CHARTS
+    def __init__(self, configuration=None, name=None):
+        UrlService.__init__(self, configuration=configuration, name=name)
+        if len(self.url) == 0:
+            self.url = "http://localhost/stub_status"
+        self.order = ORDER
+        self.definitions = CHARTS
 
-    def _formatted_data(self):
+    def _get_data(self):
         """
         Format data received from http request
         :return: dict
         """
-        raw = self._get_data().split(" ")
         try:
+            raw = self._get_raw_data().split(" ")
             return {'active': int(raw[2]),
                     'requests': int(raw[7]),
-                    'reading': int(raw[8]),
-                    'writing': int(raw[9]),
-                    'waiting': int(raw[11]),
-                    'accepts': int(raw[13]),
-                    'handled': int(raw[15])}
-        except ValueError:
+                    'reading': int(raw[11]),
+                    'writing': int(raw[13]),
+                    'waiting': int(raw[15]),
+                    'accepts': int(raw[8]),
+                    'handled': int(raw[9])}
+        except (ValueError, AttributeError):
             return None