From b9cc16b27f1ba21affef51da2a137462bce24dca Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Fri, 14 Jul 2023 17:31:05 +0800 Subject: [PATCH 1/2] unity/podMan: Provide an alternative way for pods or cgroup Signed-off-by: Hailong Liu --- source/tools/monitor/unity/collector/loop.lua | 16 ++++++++++------ source/tools/monitor/unity/etc/k8s.yaml | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/source/tools/monitor/unity/collector/loop.lua b/source/tools/monitor/unity/collector/loop.lua index 47e793de..68b19a55 100644 --- a/source/tools/monitor/unity/collector/loop.lua +++ b/source/tools/monitor/unity/collector/loop.lua @@ -16,7 +16,7 @@ local CguardDaemon = require("collector.guard.guardDaemon") local CguardSelfStat = require("collector.guard.guardSelfStat") local CpostPlugin = require("collector.postPlugin.postPlugin") local CforkRun = require("collector.execEngine.forkRun") ----local CpodFilter = require("collector.podMan.podFilter") +local CpodFilter = require("collector.podMan.podFilter") local CpodsAll = require("collector.podMan.podsAll") local Cloop = class("loop") @@ -52,11 +52,15 @@ function Cloop:loadLuaPlugin(res, proc_path, procffi) end end if res.container then - ---self._procs[c] = CpodFilter.new(res, self._proto, procffi, proc_path) - ---self._names[c] = "podFilter" - self._procs[c] = CpodsAll.new(res, self._proto, procffi, proc_path) - self._names[c] = "podMon" - + if res.container.mode == "cgroup" then + --print("mods1="..res.container.mode) + self._procs[c] = CpodFilter.new(res, self._proto, procffi, proc_path) + self._names[c] = "podFilter" + else + --print("mods2="..res.container.mode) + self._procs[c] = CpodsAll.new(res, self._proto, procffi, proc_path) + self._names[c] = "podMon" + end end print("add " .. system:keyCount(self._procs) .. " lua plugin.") end diff --git a/source/tools/monitor/unity/etc/k8s.yaml b/source/tools/monitor/unity/etc/k8s.yaml index 8b9f1690..458b90f4 100644 --- a/source/tools/monitor/unity/etc/k8s.yaml +++ b/source/tools/monitor/unity/etc/k8s.yaml @@ -25,6 +25,7 @@ outline: container: mode: "pods" + #mode:"cgroup" #"cg_cpuacct_stat" is a substitute of cg_cpuacct_proc_stat luaPlugin: ["cg_memory_fail_cnt", "cg_memory_util", "cg_memory_dcmp_latency", "cg_memory_drcm_latency", "cg_cpuacct_wait_latency", "cg_cpuacct_proc_stat", -- Gitee From fd6570e91da885aecf16722c50f1ab55e5c7a1b1 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Tue, 18 Jul 2023 11:14:19 +0800 Subject: [PATCH 2/2] proc_stat: Add cpu_util threshold warning events Signed-off-by: Hailong Liu --- .../monitor/unity/collector/proc_stat.lua | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/source/tools/monitor/unity/collector/proc_stat.lua b/source/tools/monitor/unity/collector/proc_stat.lua index e5834d75..dbdec60b 100644 --- a/source/tools/monitor/unity/collector/proc_stat.lua +++ b/source/tools/monitor/unity/collector/proc_stat.lua @@ -14,6 +14,9 @@ function CprocStat:_init_(proto, pffi, mnt, pFile) CvProc._init_(self, proto, pffi, mnt,pFile or "proc/stat") self._funs = self:setupTable() self._cpuArr = {} + self._total_warn = 0 + self._sys_warn = 0 + self._user_warn = 0 end function CprocStat:_cpuHead() @@ -23,6 +26,12 @@ end function CprocStat:_procCpu(now, last) if last then + local user_thresh = 40 + local sys_thresh = 25 + local total_thresh = 55 + local user_util = 0 + local sys_util = 0 + local warn = 0 local vs = {} local sum = 0 local index = self:_cpuHead() @@ -37,10 +46,39 @@ function CprocStat:_procCpu(now, last) local total = tonumber(sum) for i = 1, #vs do local v = tonumber(vs[i]) + + --for warn events + if index[i] == "user" or index[i] == "nice" then + user_util = user_util + v*100.0/total + end + if index[i] == "sys" or index[i] == "softirq" then + sys_util = sys_util + v*100.0/total + end + if index[i] == "idle" then + total_util = 100 - (v*100.0/total) + end + local cell = {name=index[i], value=tonumber(v * 100.0 / total)} table.insert(res, cell) end table.insert(res, {name="total", value=total}) + --warn events + if user_util > user_thresh then + self._user_warn = self._user_warn + 1 + end + local cell0 = {name="usr_warn", value=self._user_warn} + table.insert(res, cell0) + if sys_util > sys_thresh then + self._sys_warn = self._sys_warn + 1 + end + local cell1 = {name="sys_warn", value=self._sys_warn} + table.insert(res, cell1) + if total_util > user_thresh then + self._total_warn = self._total_warn + 1 + end + local cell2 = {name="total_warn", value=self._total_warn} + table.insert(res, cell2) + return res end end -- Gitee