]> arthur.barton.de Git - netdata.git/commitdiff
nginx + apache python modules
authorpaulfantom <paulfantom@gmail.com>
Wed, 22 Jun 2016 12:23:22 +0000 (14:23 +0200)
committerpaulfantom <paulfantom@gmail.com>
Wed, 22 Jun 2016 12:23:22 +0000 (14:23 +0200)
python.d/apache.chart.py [new file with mode: 0644]
python.d/nginx.chart.py [new file with mode: 0644]
python.d/phpfpm.chart.py

diff --git a/python.d/apache.chart.py b/python.d/apache.chart.py
new file mode 100644 (file)
index 0000000..9dfc52d
--- /dev/null
@@ -0,0 +1,114 @@
+# -*- coding: utf-8 -*-
+# Description: apache netdata python.d plugin
+# Author: Pawel Krupa (paulfantom)
+
+from base import UrlService
+
+# default module values (can be overridden per job in `config`)
+# update_every = 2
+# priority = 60000
+# retries = 5
+
+# default job configuration (overridden by python.d.plugin)
+# config = {'local': {
+#             'update_every': update_every,
+#             'retries': retries,
+#             'priority': priority,
+#             'url': 'http://www.apache.org/server-status?auto'
+#          }}
+
+# charts order (can be overridden if you want less charts, or different order)
+ORDER = ['bytesperreq', 'workers', 'reqpersec', 'bytespersec', 'requests', 'net', 'connections', 'conns_async']
+
+CHARTS = {
+    'bytesperreq': {
+        'options': "'' 'apache Lifetime Avg. Response Size' 'bytes/request' statistics apache.bytesperreq area",
+        'lines': [
+            {"name": "size_req",
+             "options": "'' absolute 1"},
+        ]},
+    'workers': {
+        'options': "'' 'apache Workers' 'workers' workers apache.workers stacked",
+        'lines': [
+            {"name": "idle",
+             "options": "'' absolute 1 1"},
+            {"name": "busy",
+             "options": "'' absolute 1 1"}
+        ]},
+    'reqpersec': {
+        'options': "'' 'apache Lifetime Avg. Requests/s' 'requests/s' statistics apache.reqpersec area",
+        'lines': [
+            {"name": "requests_sec",
+             "options": "'' absolute 1 1000000"}
+        ]},
+    'bytespersec': {
+        'options': "'' 'apache Lifetime Avg. Response Size' 'bytes/request' statistics apache.bytesperreq area",
+        'lines': [
+            {"name": "size_sec",
+             "options": "'' absolute 8 1000000*1000"}
+        ]},
+    'requests': {
+        'options': "''' 'apache Requests' 'requests/s' requests apache.requests line",
+        'lines': [
+            {"name": "requests",
+             "options": "'' incremental 1 1"}
+        ]},
+    'net': {
+        'options': "'' 'apache Bandwidth' 'kilobits/s' bandwidth apache.net area",
+        'lines': [
+            {"name": "sent",
+             "options": "'' incremental 8 1"}
+        ]},
+    'connections': {
+        'options': "'' 'apache Connections' 'connections' connections apache.connections line",
+        'lines': [
+            {"name": "connections",
+             "options": "'' absolute 1 1"}
+        ]},
+    'conns_async': {
+        'options': "'' 'apache Async Connections' 'connections' connections apache.conns_async stacked",
+        'lines': [
+            {"name": "keepalive",
+             "options": "'' absolute 1 1"},
+            {"name": "closing",
+             "options": "'' absolute 1 1"},
+            {"name": "writing",
+             "options": "'' absolute 1 1"},
+        ]}
+}
+
+
+class Service(UrlService):
+    url = "http://localhost/server-status?auto"
+    order = ORDER
+    charts = CHARTS
+    assignment = {"BytesPerReq": 'size_req',
+                  "IdleWorkers": 'idle',
+                  "BusyWorkers": 'busy',
+                  "ReqPerSec": 'requests_sec',
+                  "BytesPerSec": 'size_sec',
+                  "Total Accesses": 'requests',
+                  "Total kBytes": 'sent',
+                  "ConnsTotal": 'connections',
+                  "ConnsAsyncKeepAlive": 'keepalive',
+                  "ConnsAsyncClosing": 'closing',
+                  "ConnsAsyncWriting": 'writing'}
+
+    def _formatted_data(self):
+        """
+        Format data received from http request
+        :return: dict
+        """
+        raw = self._get_data().split("\n")
+        data = {}
+        for row in raw:
+            tmp = row.split(":")
+            if str(tmp[0]) in self.assignment:
+                try:
+                    data[self.assignment[tmp[0]]] = int(float(tmp[1]))
+                except (IndexError, ValueError) as a:
+                    print(a)
+                    pass
+        if len(data) == 0:
+            return None
+        return data
diff --git a/python.d/nginx.chart.py b/python.d/nginx.chart.py
new file mode 100644 (file)
index 0000000..e0acdda
--- /dev/null
@@ -0,0 +1,77 @@
+# -*- coding: utf-8 -*-
+# Description: nginx netdata python.d plugin
+# Author: Pawel Krupa (paulfantom)
+
+from base import UrlService
+
+# default module values (can be overridden per job in `config`)
+# update_every = 2
+# priority = 60000
+# retries = 5
+
+# default job configuration (overridden by python.d.plugin)
+# config = {'local': {
+#             'update_every': update_every,
+#             'retries': retries,
+#             'priority': priority,
+#             'url': 'http://localhost/stub_status'
+#          }}
+
+# charts order (can be overridden if you want less charts, or different order)
+ORDER = ['connections', 'requests', 'connection_status', 'connect_rate']
+
+CHARTS = {
+    'connections': {
+        'options': "'' 'nginx Active Connections' 'connections' nginx nginx.connections line",
+        'lines': [
+            {"name": "active",
+             "options": "'' absolute 1 1"},
+        ]},
+    'requests': {
+        'options': "'' 'nginx Requests' 'requests/s' nginx nginx.requests line",
+        'lines': [
+            {"name": "requests",
+             "options": "'' incremental 1 1"}
+        ]},
+    'connection_status': {
+        'options': "'' '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"}
+        ]},
+    'connect_rate': {
+        'options': "'' 'nginx Connections Rate' 'connections/s' nginx nginx.performance line",
+        'lines': [
+            {"name": "accepts",
+             "options": "'accepted' incremental 1 1"},
+            {"name": "handled",
+             "options": "'' incremental 1 1"}
+        ]}
+}
+
+
+class Service(UrlService):
+    url = "http://localhost/stub_status"
+    order = ORDER
+    charts = CHARTS
+
+    def _formatted_data(self):
+        """
+        Format data received from http request
+        :return: dict
+        """
+        raw = self._get_data().split(" ")
+        try:
+            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:
+            return None
index 31bd2fdbb748ed498139b318ecf3d2ff7391fae7..0ccf6800faf0c4dbb8029a5ff2fd63343d196d09 100755 (executable)
@@ -74,4 +74,6 @@ class Service(UrlService):
                     data[self.assignment[tmp[0]]] = int(tmp[1])
                 except (IndexError, ValueError) as a:
                     pass
+        if len(data) == 0:
+            return None
         return data