diff --git a/source/tools/monitor/unity/collector/loop.lua b/source/tools/monitor/unity/collector/loop.lua index 47e793ded8ae19fe1eb7a5740ca2b9d2206d828f..68b19a557bd4eedd50ed18326bd38de9c4e89ba6 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/collector/proc_stat.lua b/source/tools/monitor/unity/collector/proc_stat.lua index e5834d75d8f3ad3d49670a55bb71205005fa3b78..dbdec60beadc78c5404c8dedf41e94cc57e299ef 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 diff --git a/source/tools/monitor/unity/etc/k8s.yaml b/source/tools/monitor/unity/etc/k8s.yaml index 8b9f1690fcefbbeb34e9f2125a534ffbc9b4800f..458b90f49bbf998e272c87eb67977a2e2f16eaca 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",