@cryptotaxi247 / netdata-1 / commits / 365417086

apache plugin: renames job to "lighttpd" if "IdleServers" in response

Ilya committed Jun 12, 2017 at 13:13 UTC 365417086e659820570e89c93439b1dc96b05860
1 file changed +45 -28
python.d/apache.chart.py
+45 -28
@@ -22,7 +22,8 @@ ORDER = ['requests', 'connections', 'conns_async', 'net', 'workers', 'reqpersec'
22
23 CHARTS = {
24 'bytesperreq': {
25 - 'options': [None, 'apache Lifetime Avg. Response Size', 'bytes/request', 'statistics', 'apache.bytesperreq', 'area'],
25 + 'options': [None, 'apache Lifetime Avg. Response Size', 'bytes/request',
26 + 'statistics', 'apache.bytesperreq', 'area'],
27 'lines': [
28 ["size_req"]
29 ]},
@@ -30,15 +31,19 @@ CHARTS = {
31 'options': [None, 'apache Workers', 'workers', 'workers', 'apache.workers', 'stacked'],
32 'lines': [
33 ["idle"],
33 - ["busy"]
34 + ["idle_servers", 'idle'],
35 + ["busy"],
36 + ["busy_servers", 'busy']
37 ]},
38 'reqpersec': {
36 - 'options': [None, 'apache Lifetime Avg. Requests/s', 'requests/s', 'statistics', 'apache.reqpersec', 'area'],
39 + 'options': [None, 'apache Lifetime Avg. Requests/s', 'requests/s', 'statistics',
40 + 'apache.reqpersec', 'area'],
41 'lines': [
42 ["requests_sec"]
43 ]},
44 'bytespersec': {
41 - 'options': [None, 'apache Lifetime Avg. Bandwidth/s', 'kilobytes/s', 'statistics', 'apache.bytesperreq', 'area'],
45 + 'options': [None, 'apache Lifetime Avg. Bandwidth/s', 'kilobytes/s', 'statistics',
46 + 'apache.bytesperreq', 'area'],
47 'lines': [
48 ["size_sec", None, 'absolute', 1, 1000]
49 ]},
@@ -66,43 +71,55 @@ CHARTS = {
71 ]}
72 }
73
74 +ASSIGNMENT = {"BytesPerReq": 'size_req',
75 + "IdleWorkers": 'idle',
76 + "IdleServers": 'idle_servers',
77 + "BusyWorkers": 'busy',
78 + "BusyServers": 'busy_servers',
79 + "ReqPerSec": 'requests_sec',
80 + "BytesPerSec": 'size_sec',
81 + "Total Accesses": 'requests',
82 + "Total kBytes": 'sent',
83 + "ConnsTotal": 'connections',
84 + "ConnsAsyncKeepAlive": 'keepalive',
85 + "ConnsAsyncClosing": 'closing',
86 + "ConnsAsyncWriting": 'writing'}
87 +
88
89 class Service(UrlService):
90 def __init__(self, configuration=None, name=None):
91 UrlService.__init__(self, configuration=configuration, name=name)
73 - if len(self.url) == 0:
74 - self.url = "http://localhost/server-status?auto"
92 self.order = ORDER
93 self.definitions = CHARTS
77 - self.assignment = {"BytesPerReq": 'size_req',
78 - "IdleWorkers": 'idle',
79 - "BusyWorkers": 'busy',
80 - "ReqPerSec": 'requests_sec',
81 - "BytesPerSec": 'size_sec',
82 - "Total Accesses": 'requests',
83 - "Total kBytes": 'sent',
84 - "ConnsTotal": 'connections',
85 - "ConnsAsyncKeepAlive": 'keepalive',
86 - "ConnsAsyncClosing": 'closing',
87 - "ConnsAsyncWriting": 'writing'}
94 + self.url = self.configuration.get('url', 'http://localhost/server-status?auto')
95 +
96 + def check(self):
97 + if UrlService.check(self):
98 + if 'idle_servers' in self._data_from_check:
99 + self.__module__ = 'lighttpd'
100 + for chart in self.definitions:
101 + self.definitions[chart]['options'][1] = self.definitions[chart]['options'][1].replace('apache',
102 + 'lighttpd')
103 + self.definitions[chart]['options'][4] = self.definitions[chart]['options'][4].replace('apache',
104 + 'lighttpd')
105 + return True
106 + return False
107
108 def _get_data(self):
109 """
110 Format data received from http request
111 :return: dict
112 """
94 - try:
95 - raw = self._get_raw_data().split("\n")
96 - except AttributeError:
113 + raw_data = self._get_raw_data()
114 + if not raw_data:
115 return None
98 - data = {}
99 - for row in raw:
116 + data = dict()
117 +
118 + for row in raw_data.split('\n'):
119 tmp = row.split(":")
101 - if str(tmp[0]) in self.assignment:
120 + if tmp[0] in ASSIGNMENT:
121 try:
103 - data[self.assignment[tmp[0]]] = int(float(tmp[1]))
122 + data[ASSIGNMENT[tmp[0]]] = int(float(tmp[1]))
123 except (IndexError, ValueError):
105 - pass
106 - if len(data) == 0:
107 - return None
108 - return data
124 + continue
125 + return data or None