This commit is contained in:
midoks
2023-02-11 17:06:24 +08:00
parent 854e34a90c
commit 18498813c6
2 changed files with 14 additions and 14 deletions
+13 -8
View File
@@ -20,18 +20,18 @@ local waf_site_config = require "waf_site"
C:setConfData(waf_config, waf_site_config)
C:setDebug(true)
if ngx.worker.id() == 0 then
C:cron()
end
-- C:D("init worker"..tostring(ngx.worker.id()))
local function timer_stats_total_log(premature)
local function waf_timer_stats_total_log(premature)
C:timer_stats_total()
end
local waf_clean_expire_data = function(premature)
C:clean_log()
end
ngx.shared.waf_limit:set("cpu_usage", 0, 10)
function timer_every_get_cpu(premature)
function waf_timer_every_get_cpu(premature)
local cpu_percent = C:read_file_body(waf_root.."/cpu.info")
-- C:D("cpu_usage:"..tostring(cpu_percent ))
if cpu_percent then
@@ -41,7 +41,12 @@ function timer_every_get_cpu(premature)
end
end
ngx.timer.every(5, timer_every_get_cpu)
if ngx.worker.id() == 0 then
-- 异步执行
ngx.timer.every(3, timer_stats_total_log)
ngx.timer.every(5, waf_timer_every_get_cpu)
-- 异步执行
ngx.timer.every(3, waf_timer_stats_total_log)
ngx.timer.every(10, waf_clean_expire_data)
C:cron()
end
+1 -6
View File
@@ -51,11 +51,7 @@ end
-- 后台任务
function _M.cron(self)
local timer_every_get_data = function(premature)
self:clean_log()
end
ngx.timer.every(10, timer_every_get_data)
local timer_every_import_data = function(premature)
local llen, _ = ngx.shared.waf_limit:llen('waf_limit_logs')
@@ -70,7 +66,6 @@ function _M.cron(self)
local stmt2 = db:prepare[[INSERT INTO logs(time, ip, domain, server_name, method, status_code, uri, user_agent, rule_name, reason)
VALUES(:time, :ip, :domain, :server_name, :method, :status_code, :uri, :user_agent, :rule_name, :reason)]]
if not stmt2 then
self:D("waf timer db:prepare fail!:"..tostring(stmt2))
return false