2022-10-12 01:49:57 -04:00
|
|
|
|
2022-10-14 00:41:32 -04:00
|
|
|
local json = require "cjson"
|
2022-10-12 01:49:57 -04:00
|
|
|
|
2022-10-12 05:18:51 -04:00
|
|
|
local waf_root = "{$WAF_ROOT}"
|
|
|
|
|
local cpath = waf_root.."/waf/"
|
|
|
|
|
|
|
|
|
|
local __C = require "common"
|
2022-10-14 05:50:26 -04:00
|
|
|
local C = __C:getInstance()
|
|
|
|
|
|
2022-10-12 05:18:51 -04:00
|
|
|
|
2022-10-14 09:41:25 -04:00
|
|
|
local function timer_stats_total_log(premature)
|
2022-10-14 05:50:26 -04:00
|
|
|
C:timer_stats_total()
|
2022-10-12 05:18:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2022-10-14 05:50:26 -04:00
|
|
|
ngx.shared.waf_limit:set("cpu_usage", 0, 10)
|
2022-10-12 01:49:57 -04:00
|
|
|
function timer_every_get_cpu(premature)
|
2022-10-15 11:28:36 -04:00
|
|
|
local cpu_percent = C:read_file_body(waf_root.."/cpu.info")
|
|
|
|
|
if cpu_percent then
|
2022-10-15 11:44:53 -04:00
|
|
|
ngx.shared.waf_limit:set("cpu_usage", tonumber(cpu_percent), 10)
|
2022-10-15 11:28:36 -04:00
|
|
|
else
|
|
|
|
|
ngx.shared.waf_limit:set("cpu_usage", 0, 10)
|
|
|
|
|
end
|
2022-10-12 01:49:57 -04:00
|
|
|
end
|
2022-10-14 00:41:32 -04:00
|
|
|
|
2022-10-12 01:49:57 -04:00
|
|
|
if 0 == ngx.worker.id() then
|
|
|
|
|
ngx.timer.every(5, timer_every_get_cpu)
|
2022-10-12 05:18:51 -04:00
|
|
|
|
|
|
|
|
-- 异步执行
|
2022-10-14 09:41:25 -04:00
|
|
|
ngx.timer.every(3, timer_stats_total_log)
|
2022-10-12 01:49:57 -04:00
|
|
|
end
|