Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/op_waf/waf/lua/init_worker.lua

43 lines
911 B

3 years ago
3 years ago
local json = require "cjson"
3 years ago
local waf_root = "{$WAF_ROOT}"
local cpath = waf_root.."/waf/"
local __C = require "common"
local C = __C:new()
local function write_file_clear(filename, body)
fp = io.open(filename,'w')
if fp == nil then
return nil
end
fp:write(body)
fp:flush()
fp:close()
return true
end
local function timer_at_inc_log(premature)
local total_path = cpath .. 'total.json'
3 years ago
local tbody = ngx.shared.waf_waf_limit:get(total_path)
if not tbody then
return false
end
3 years ago
return write_file_clear(total_path, tbody)
end
3 years ago
ngx.shared.waf_waf_limit:set("cpu_usage", 0, 10)
3 years ago
function timer_every_get_cpu(premature)
cpu_percent = 80
3 years ago
ngx.shared.waf_waf_limit:set("cpu_usage", cpu_percent, 10)
3 years ago
end
3 years ago
3 years ago
if 0 == ngx.worker.id() then
ngx.timer.every(5, timer_every_get_cpu)
-- 异步执行
ngx.timer.every(3, timer_at_inc_log)
3 years ago
end