This commit is contained in:
midoks
2023-02-11 23:25:29 +08:00
parent 62ffc94b69
commit 560d482f31
4 changed files with 47 additions and 14 deletions
+9 -9
View File
@@ -12,28 +12,28 @@ end
local json = require "cjson"
local __C = require "waf_common"
local C = __C:getInstance()
local __WAF_C = require "waf_common"
local WAF_C = __WAF_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)
WAF_C:setConfData(waf_config, waf_site_config)
WAF_C:setDebug(true)
-- C:D("init worker"..tostring(ngx.worker.id()))
local function waf_timer_stats_total_log(premature)
C:timer_stats_total()
WAF_C:timer_stats_total()
end
local waf_clean_expire_data = function(premature)
C:clean_log()
WAF_C:clean_log()
end
ngx.shared.waf_limit:set("cpu_usage", 0, 10)
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 ))
local cpu_percent = WAF_C:read_file_body(waf_root.."/cpu.info")
-- WAF_C:D("cpu_usage:"..tostring(cpu_percent ))
if cpu_percent then
ngx.shared.waf_limit:set("cpu_usage", tonumber(cpu_percent), 10)
else
@@ -48,5 +48,5 @@ if ngx.worker.id() == 0 then
ngx.timer.every(3, waf_timer_stats_total_log)
ngx.timer.every(10, waf_clean_expire_data)
C:cron()
WAF_C:cron()
end
+17
View File
@@ -254,11 +254,22 @@ def initDreplace():
file_list = [
'webstats_common.lua',
'webstats_log.lua',
'webstats_worker.lua',
]
for fl in file_list:
loadLuaFile(fl)
root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
webstats_worker_src_file = lua_dir = getServerDir() + "/lua/webstats_worker.lua"
webstats_worker_dst_file = root_worker_dir + '/webstats_worker.lua'
content = mw.readFile(webstats_worker_src_file)
content = content.replace('{$SERVER_APP}', getServerDir())
content = content.replace('{$ROOT_PATH}', mw.getServerDir())
mw.writeFile(webstats_worker_dst_file, content)
mw.opLuaInitWorkerFile()
loadConfigFile()
loadLuaSiteFile()
loadDebugLogFile()
@@ -290,6 +301,12 @@ def stop():
if os.path.exists(path):
os.remove(path)
root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
webstats_worker_dst_file = root_worker_dir + '/webstats_worker.lua'
if os.path.exists(webstats_worker_dst_file):
os.remove(webstats_worker_dst_file)
mw.opLuaInitWorkerFile()
import tool_task
tool_task.removeBgTask()
+1 -5
View File
@@ -46,10 +46,6 @@ end
function _M.getInstance(self)
if rawget(self, "instance") == nil then
rawset(self, "instance", self.new())
if 0 == ngx.worker.id() then
self:cron()
end
end
assert(self.instance ~= nil)
return self.instance
@@ -276,7 +272,7 @@ function _M.cron(self)
local url_stats = {}
local time_key = self:get_store_key()
for site_k, site_v in ipairs(sites) do
local input_sn = site_v["name"]
-- self:D("input_sn:"..input_sn)
+20
View File
@@ -0,0 +1,20 @@
local cpath = "{$SERVER_APP}/lua/"
if not package.cpath:find(cpath) then
package.cpath = cpath .. "?.so;" .. package.cpath
end
if not package.path:find(cpath) then
package.path = cpath .. "?.lua;" .. package.path
end
local __WS_C = require "webstats_common"
local WS_C = __WS_C:getInstance()
WS_C:cronPre()
local webstats_cron_pre = function(premature)
WS_C:cronPre()
end
if ngx.worker.id() == 0 then
ngx.timer.every(60, webstats_cron_pre)
WS_C:cron()
end