Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinit.lua
More file actions
Latest commit
77 lines (64 loc) · 2.37 KB
/
Copy pathinit.lua
File metadata and controls
77 lines (64 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
localframework=require('framework')
localurl=require('url')
localPlugin=framework.Plugin
localWebRequestDataSource=framework.WebRequestDataSource
localAccumulator=framework.Accumulator
localgsplit=framework.string.gsplit
localsplit=framework.string.split
localauth=framework.util.auth
localparams=framework.params
localoptions=url.parse(params.url)
options.path=options.path..'?auto' -- server-status?auto for text/plain output
options.auth=auth(params.username, params.password)
options.wait_for_end=true
localmapping= {
['BusyWorkers'] ='APACHE_BUSY_WORKERS',
['IdleWorkers'] ='APACHE_IDLE_WORKERS',
['Total Accesses'] ='APACHE_REQUESTS',
['CPULoad'] ='APACHE_CPU',
['Total kBytes'] ='APACHE_BYTES'
}
localdata_source=WebRequestDataSource:new(options)
localacc=Accumulator:new()
localplugin=Plugin:new(params, data_source)
functionplugin:onParseValues(data, _)
-- Capture metrics
localresult= {}
forvingsplit(data, "\n") do
localm=split(v, ":")
localkey, val=unpack(m)
if (keyandval) then
localmetric=mapping[key]
ifmetricthen
result[metric] =tonumber(val) or-1
end
end
end
-- CPU Load calculations
localcpu_load=result['APACHE_CPU'] or0
if (cpu_load>1) then
cpu_load=cpu_load/100
end
result['APACHE_CPU'] =cpu_load
-- Requests calculation
localrequests=acc:accumulate('APACHE_REQUESTS', result['APACHE_REQUESTS'])
result['APACHE_REQUESTS'] =requests
-- Total Bytes calculation
-- Because of the interval cut off lines, on a really slow site you will get 0's
-- the, use the previous value if that happens
locallast_total_bytes=acc:get('APACHE_BYTES')
localtotal_bytes=acc:accumulate('APACHE_BYTES', result['APACHE_BYTES'] *1024)
ifrequests>0andtotal_bytes==0then
total_bytes=last_total_bytes
end
result['APACHE_BYTES'] =total_bytes
-- Total Bytes Per Request calculation
localbytes_per_req= (requests>0) and (total_bytes/requests) or0
result['APACHE_BYTES_PER_REQUEST'] =bytes_per_req
-- Busy Ratio calculation
localtotal_workers= (result['APACHE_BUSY_WORKERS'] or0) + (result['APACHE_IDLE_WORKERS'] or0)
localbusy_ratio=total_workersandresult['APACHE_BUSY_WORKERS'] /total_workersor0
result['APACHE_BUSY_RATIO'] =busy_ratio
returnresult
end
plugin:run()