@cryptotaxi247 / netdata-1 / commits / 4dea6a8b9

nginx + apache python modules

paulfantom committed Jun 22, 2016 at 14:23 UTC 4dea6a8b9885ba1bc2f839cdd3a979de1de6b2f1
3 files changed +193
python.d/apache.chart.py new
+114
@@ -0,0 +1,114 @@
1 +# -*- coding: utf-8 -*-
2 +# Description: apache netdata python.d plugin
3 +# Author: Pawel Krupa (paulfantom)
4 +
5 +from base import UrlService
6 +
7 +# default module values (can be overridden per job in `config`)
8 +# update_every = 2
9 +# priority = 60000
10 +# retries = 5
11 +
12 +# default job configuration (overridden by python.d.plugin)
13 +# config = {'local': {
14 +# 'update_every': update_every,
15 +# 'retries': retries,
16 +# 'priority': priority,
17 +# 'url': 'http://www.apache.org/server-status?auto'
18 +# }}
19 +
20 +# charts order (can be overridden if you want less charts, or different order)
21 +ORDER = ['bytesperreq', 'workers', 'reqpersec', 'bytespersec', 'requests', 'net', 'connections', 'conns_async']
22 +
23 +CHARTS = {
24 + 'bytesperreq': {
25 + 'options': "'' 'apache Lifetime Avg. Response Size' 'bytes/request' statistics apache.bytesperreq area",
26 + 'lines': [
27 + {"name": "size_req",
28 + "options": "'' absolute 1"},
29 + ]},
30 + 'workers': {
31 + 'options': "'' 'apache Workers' 'workers' workers apache.workers stacked",
32 + 'lines': [
33 + {"name": "idle",
34 + "options": "'' absolute 1 1"},
35 + {"name": "busy",
36 + "options": "'' absolute 1 1"}
37 + ]},
38 + 'reqpersec': {
39 + 'options': "'' 'apache Lifetime Avg. Requests/s' 'requests/s' statistics apache.reqpersec area",
40 + 'lines': [
41 + {"name": "requests_sec",
42 + "options": "'' absolute 1 1000000"}
43 + ]},
44 + 'bytespersec': {
45 + 'options': "'' 'apache Lifetime Avg. Response Size' 'bytes/request' statistics apache.bytesperreq area",
46 + 'lines': [
47 + {"name": "size_sec",
48 + "options": "'' absolute 8 1000000*1000"}
49 + ]},
50 + 'requests': {
51 + 'options': "''' 'apache Requests' 'requests/s' requests apache.requests line",
52 + 'lines': [
53 + {"name": "requests",
54 + "options": "'' incremental 1 1"}
55 + ]},
56 + 'net': {
57 + 'options': "'' 'apache Bandwidth' 'kilobits/s' bandwidth apache.net area",
58 + 'lines': [
59 + {"name": "sent",
60 + "options": "'' incremental 8 1"}
61 + ]},
62 + 'connections': {
63 + 'options': "'' 'apache Connections' 'connections' connections apache.connections line",
64 + 'lines': [
65 + {"name": "connections",
66 + "options": "'' absolute 1 1"}
67 + ]},
68 + 'conns_async': {
69 + 'options': "'' 'apache Async Connections' 'connections' connections apache.conns_async stacked",
70 + 'lines': [
71 + {"name": "keepalive",
72 + "options": "'' absolute 1 1"},
73 + {"name": "closing",
74 + "options": "'' absolute 1 1"},
75 + {"name": "writing",
76 + "options": "'' absolute 1 1"},
77 + ]}
78 +}
79 +
80 +
81 +class Service(UrlService):
82 + url = "http://localhost/server-status?auto"
83 + order = ORDER
84 + charts = CHARTS
85 + assignment = {"BytesPerReq": 'size_req',
86 + "IdleWorkers": 'idle',
87 + "BusyWorkers": 'busy',
88 + "ReqPerSec": 'requests_sec',
89 + "BytesPerSec": 'size_sec',
90 + "Total Accesses": 'requests',
91 + "Total kBytes": 'sent',
92 + "ConnsTotal": 'connections',
93 + "ConnsAsyncKeepAlive": 'keepalive',
94 + "ConnsAsyncClosing": 'closing',
95 + "ConnsAsyncWriting": 'writing'}
96 +
97 + def _formatted_data(self):
98 + """
99 + Format data received from http request
100 + :return: dict
101 + """
102 + raw = self._get_data().split("\n")
103 + data = {}
104 + for row in raw:
105 + tmp = row.split(":")
106 + if str(tmp[0]) in self.assignment:
107 + try:
108 + data[self.assignment[tmp[0]]] = int(float(tmp[1]))
109 + except (IndexError, ValueError) as a:
110 + print(a)
111 + pass
112 + if len(data) == 0:
113 + return None
114 + return data
python.d/nginx.chart.py new
+77
@@ -0,0 +1,77 @@
1 +# -*- coding: utf-8 -*-
2 +# Description: nginx netdata python.d plugin
3 +# Author: Pawel Krupa (paulfantom)
4 +
5 +from base import UrlService
6 +
7 +# default module values (can be overridden per job in `config`)
8 +# update_every = 2
9 +# priority = 60000
10 +# retries = 5
11 +
12 +# default job configuration (overridden by python.d.plugin)
13 +# config = {'local': {
14 +# 'update_every': update_every,
15 +# 'retries': retries,
16 +# 'priority': priority,
17 +# 'url': 'http://localhost/stub_status'
18 +# }}
19 +
20 +# charts order (can be overridden if you want less charts, or different order)
21 +ORDER = ['connections', 'requests', 'connection_status', 'connect_rate']
22 +
23 +CHARTS = {
24 + 'connections': {
25 + 'options': "'' 'nginx Active Connections' 'connections' nginx nginx.connections line",
26 + 'lines': [
27 + {"name": "active",
28 + "options": "'' absolute 1 1"},
29 + ]},
30 + 'requests': {
31 + 'options': "'' 'nginx Requests' 'requests/s' nginx nginx.requests line",
32 + 'lines': [
33 + {"name": "requests",
34 + "options": "'' incremental 1 1"}
35 + ]},
36 + 'connection_status': {
37 + 'options': "'' 'nginx Active Connections by Status' 'connections' nginx nginx.connection.status line",
38 + 'lines': [
39 + {"name": "reading",
40 + "options": "'' absolute 1 1"},
41 + {"name": "writing",
42 + "options": "'' absolute 1 1"},
43 + {"name": "waiting",
44 + "options": "'' absolute 1 1"}
45 + ]},
46 + 'connect_rate': {
47 + 'options': "'' 'nginx Connections Rate' 'connections/s' nginx nginx.performance line",
48 + 'lines': [
49 + {"name": "accepts",
50 + "options": "'accepted' incremental 1 1"},
51 + {"name": "handled",
52 + "options": "'' incremental 1 1"}
53 + ]}
54 +}
55 +
56 +
57 +class Service(UrlService):
58 + url = "http://localhost/stub_status"
59 + order = ORDER
60 + charts = CHARTS
61 +
62 + def _formatted_data(self):
63 + """
64 + Format data received from http request
65 + :return: dict
66 + """
67 + raw = self._get_data().split(" ")
68 + try:
69 + return {'active': int(raw[2]),
70 + 'requests': int(raw[7]),
71 + 'reading': int(raw[8]),
72 + 'writing': int(raw[9]),
73 + 'waiting': int(raw[11]),
74 + 'accepts': int(raw[13]),
75 + 'handled': int(raw[15])}
76 + except ValueError:
77 + return None
python.d/phpfpm.chart.py
+2
@@ -74,4 +74,6 @@ class Service(UrlService):
74 data[self.assignment[tmp[0]]] = int(tmp[1])
75 except (IndexError, ValueError) as a:
76 pass
77 + if len(data) == 0:
78 + return None
79 return data