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

47 lines
1.2 KiB

local waf_root = "{$WAF_ROOT}"
local waf_cpath = waf_root.."/waf/lua/?.lua;"..waf_root.."/waf/conf/?.lua;"..waf_root.."/waf/html/?.lua;"
local waf_sopath = waf_root.."/waf/conf/?.so;"
3 years ago
if not package.path:find(waf_cpath) then
package.path = waf_cpath .. package.path
end
3 years ago
if not package.cpath:find(waf_sopath) then
package.cpath = waf_sopath .. package.cpath
end
local json = require "cjson"
2 years ago
local __C = require "waf_common"
3 years ago
local C = __C:getInstance()
local waf_config = require "waf_config"
local waf_site_config = require "waf_site"
C:setConfData(waf_config, waf_site_config)
C:setDebug(true)
2 years ago
if ngx.worker.id() == 0 then
C:cron()
end
-- C:D("init worker"..tostring(ngx.worker.id()))
3 years ago
local function timer_stats_total_log(premature)
3 years ago
C:timer_stats_total()
end
3 years ago
ngx.shared.waf_limit:set("cpu_usage", 0, 10)
3 years ago
function timer_every_get_cpu(premature)
local cpu_percent = C:read_file_body(waf_root.."/cpu.info")
2 years ago
-- C:D("cpu_usage:"..tostring(cpu_percent ))
if cpu_percent then
ngx.shared.waf_limit:set("cpu_usage", tonumber(cpu_percent), 10)
else
ngx.shared.waf_limit:set("cpu_usage", 0, 10)
end
3 years ago
end
3 years ago
2 years ago
ngx.timer.every(5, timer_every_get_cpu)
2 years ago
-- 异步执行
ngx.timer.every(3, timer_stats_total_log)