55
66from bases .FrameworkServices .UrlService import UrlService
77
8- # default module values (can be overridden per job in `config`)
9- # update_every = 2
10- priority = 60000
118
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 = [ 'requests' , 'connections' , 'conns_async' , 'net' , 'workers' , 'reqpersec' , 'bytespersec' , 'bytesperreq' ]
9+ ORDER = [
10+ 'requests' ,
11+ 'connections' ,
12+ 'conns_async' ,
13+ 'net' ,
14+ 'workers' ,
15+ 'reqpersec' ,
16+ 'bytespersec' ,
17+ 'bytesperreq' ,
18+ ]
2219
2320CHARTS = {
2421 'bytesperreq' : {
25- 'options' : [None , 'apache Lifetime Avg. Response Size' , 'bytes/request ' ,
22+ 'options' : [None , 'Lifetime Avg. Request Size' , 'KiB ' ,
2623 'statistics' , 'apache.bytesperreq' , 'area' ],
2724 'lines' : [
28- ['size_req' ]
25+ ['size_req' , 'size' , 'absolute' , 1 , 1024 * 100000 ]
2926 ]},
3027 'workers' : {
31- 'options' : [None , 'apache Workers' , 'workers' , 'workers' , 'apache.workers' , 'stacked' ],
28+ 'options' : [None , 'Workers' , 'workers' , 'workers' , 'apache.workers' , 'stacked' ],
3229 'lines' : [
3330 ['idle' ],
3431 ['busy' ],
3532 ]},
3633 'reqpersec' : {
37- 'options' : [None , 'apache Lifetime Avg. Requests/s' , 'requests/s' , 'statistics' ,
34+ 'options' : [None , 'Lifetime Avg. Requests/s' , 'requests/s' , 'statistics' ,
3835 'apache.reqpersec' , 'area' ],
3936 'lines' : [
40- ['requests_sec' ]
37+ ['requests_sec' , 'requests' , 'absolute' , 1 , 100000 ]
4138 ]},
4239 'bytespersec' : {
43- 'options' : [None , 'apache Lifetime Avg. Bandwidth/s' , 'kilobits/s' , 'statistics' ,
40+ 'options' : [None , 'Lifetime Avg. Bandwidth/s' , 'kilobits/s' , 'statistics' ,
4441 'apache.bytesperreq' , 'area' ],
4542 'lines' : [
46- ['size_sec' , None , 'absolute' , 8 , 1000 ]
43+ ['size_sec' , None , 'absolute' , 8 , 1000 * 100000 ]
4744 ]},
4845 'requests' : {
49- 'options' : [None , 'apache Requests' , 'requests/s' , 'requests' , 'apache.requests' , 'line' ],
46+ 'options' : [None , 'Requests' , 'requests/s' , 'requests' , 'apache.requests' , 'line' ],
5047 'lines' : [
5148 ['requests' , None , 'incremental' ]
5249 ]},
5350 'net' : {
54- 'options' : [None , 'apache Bandwidth' , 'kilobits/s' , 'bandwidth' , 'apache.net' , 'area' ],
51+ 'options' : [None , 'Bandwidth' , 'kilobits/s' , 'bandwidth' , 'apache.net' , 'area' ],
5552 'lines' : [
5653 ['sent' , None , 'incremental' , 8 , 1 ]
5754 ]},
5855 'connections' : {
59- 'options' : [None , 'apache Connections' , 'connections' , 'connections' , 'apache.connections' , 'line' ],
56+ 'options' : [None , 'Connections' , 'connections' , 'connections' , 'apache.connections' , 'line' ],
6057 'lines' : [
6158 ['connections' ]
6259 ]},
6360 'conns_async' : {
64- 'options' : [None , 'apache Async Connections' , 'connections' , 'connections' , 'apache.conns_async' , 'stacked' ],
61+ 'options' : [None , 'Async Connections' , 'connections' , 'connections' , 'apache.conns_async' , 'stacked' ],
6562 'lines' : [
6663 ['keepalive' ],
6764 ['closing' ],
8582 'ConnsAsyncWriting' : 'writing'
8683}
8784
85+ FLOAT_VALUES = [
86+ 'BytesPerReq' ,
87+ 'ReqPerSec' ,
88+ 'BytesPerSec' ,
89+ ]
90+
91+ LIGHTTPD_MARKER = 'idle_servers'
92+
8893
8994class Service (UrlService ):
9095 def __init__ (self , configuration = None , name = None ):
@@ -95,20 +100,15 @@ def __init__(self, configuration=None, name=None):
95100
96101 def check (self ):
97102 self ._manager = self ._build_manager ()
103+
98104 data = self ._get_data ()
105+
99106 if not data :
100107 return None
101108
102- if 'idle_servers' in data :
103- self .module_name = 'lighttpd'
104- for chart in self .definitions :
105- if chart == 'workers' :
106- lines = self .definitions [chart ]['lines' ]
107- lines [0 ] = ['idle_servers' , 'idle' ]
108- lines [1 ] = ['busy_servers' , 'busy' ]
109- opts = self .definitions [chart ]['options' ]
110- opts [1 ] = opts [1 ].replace ('apache' , 'lighttpd' )
111- opts [4 ] = opts [4 ].replace ('apache' , 'lighttpd' )
109+ if LIGHTTPD_MARKER in data :
110+ self .turn_into_lighttpd ()
111+
112112 return True
113113
114114 def _get_data (self ):
@@ -117,15 +117,44 @@ def _get_data(self):
117117 :return: dict
118118 """
119119 raw_data = self ._get_raw_data ()
120+
120121 if not raw_data :
121122 return None
123+
122124 data = dict ()
123125
124- for row in raw_data .split ('\n ' ):
125- tmp = row .split (':' )
126- if tmp [0 ] in ASSIGNMENT :
127- try :
128- data [ASSIGNMENT [tmp [0 ]]] = int (float (tmp [1 ]))
129- except (IndexError , ValueError ):
130- continue
126+ for line in raw_data .split ('\n ' ):
127+ try :
128+ parse_line (line , data )
129+ except ValueError :
130+ continue
131+
131132 return data or None
133+
134+ def turn_into_lighttpd (self ):
135+ self .module_name = 'lighttpd'
136+ for chart in self .definitions :
137+ if chart == 'workers' :
138+ lines = self .definitions [chart ]['lines' ]
139+ lines [0 ] = ['idle_servers' , 'idle' ]
140+ lines [1 ] = ['busy_servers' , 'busy' ]
141+ opts = self .definitions [chart ]['options' ]
142+ opts [1 ] = opts [1 ].replace ('apache' , 'lighttpd' )
143+ opts [4 ] = opts [4 ].replace ('apache' , 'lighttpd' )
144+
145+
146+ def parse_line (line , data ):
147+ parts = line .split (':' )
148+
149+ if len (parts ) != 2 :
150+ return
151+
152+ key , value = parts [0 ], parts [1 ]
153+
154+ if key not in ASSIGNMENT :
155+ return
156+
157+ if key in FLOAT_VALUES :
158+ data [ASSIGNMENT [key ]] = int ((float (value ) * 100000 ))
159+ else :
160+ data [ASSIGNMENT [key ]] = int (value )
0 commit comments