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' local tbody = ngx.shared.limit:get(total_path) if not tbody then return false end return write_file_clear(total_path,tbody) end ngx.shared.limit:set("cpu_usage", 0, 10) local function excute_cmd(cmd) local t = io.popen(cmd) local ret = t:read("*all") return ret end function timer_every_get_cpu(premature) cpu_percent = 80 ngx.shared.limit:set("cpu_usage", cpu_percent, 10) end if 0 == ngx.worker.id() then ngx.timer.every(5, timer_every_get_cpu) -- 异步执行 ngx.timer.every(3, timer_at_inc_log) end