From 2dbda3e6dd97bf091d6babfd4f0f73cf71cf2729 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 13 Feb 2023 01:58:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96,Linux=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E5=8A=A0=E5=85=A5=E5=88=B0=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=8E=B7=E5=8F=96cpu=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/op_waf/tool_task.py | 7 ++++++- plugins/op_waf/waf/lua/init_worker.lua | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/plugins/op_waf/tool_task.py b/plugins/op_waf/tool_task.py index 52d37e6e6..1ee26c173 100644 --- a/plugins/op_waf/tool_task.py +++ b/plugins/op_waf/tool_task.py @@ -54,7 +54,9 @@ def createBgTask(): "period": "minute-n", "minute-n": "1", } - createBgTaskByName(getPluginName(), args) + + if mw.isAppleSystem(): + createBgTaskByName(getPluginName(), args) def createBgTaskByName(name, args): @@ -134,6 +136,9 @@ logs_file=$plugin_path/${rname}.log def removeBgTask(): + if not mw.isAppleSystem(): + return False + cfg_list = getConfigData() for x in range(len(cfg_list)): cfg = cfg_list[x] diff --git a/plugins/op_waf/waf/lua/init_worker.lua b/plugins/op_waf/waf/lua/init_worker.lua index f9fdedf06..26c15bb80 100644 --- a/plugins/op_waf/waf/lua/init_worker.lua +++ b/plugins/op_waf/waf/lua/init_worker.lua @@ -34,21 +34,22 @@ ngx.shared.waf_limit:set("cpu_usage", 0, 10) function waf_timer_every_get_cpu(premature) if WAF_C:file_exists('/proc/stat') then local lua_cpu_percent = WAF_C:get_cpu_percent() - WAF_C:D("lua_cpu_percent:"..tostring(lua_cpu_percent)) - end - - 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) + -- WAF_C:D("lua_cpu_percent:"..tostring(lua_cpu_percent)) + ngx.shared.waf_limit:set("cpu_usage", math.floor(lua_cpu_percent), 10) else - ngx.shared.waf_limit:set("cpu_usage", 0, 10) + 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 + ngx.shared.waf_limit:set("cpu_usage", 0, 10) + end end end if ngx.worker.id() == 0 then - ngx.timer.every(5, waf_timer_every_get_cpu) + ngx.timer.every(6, waf_timer_every_get_cpu) -- 异步执行 ngx.timer.every(3, waf_timer_stats_total_log) ngx.timer.every(10, waf_clean_expire_data)