diff --git a/source/tools/monitor/unity/collector/container/cg_cpu_cfs_quota.lua b/source/tools/monitor/unity/collector/container/cg_cpu_cfs_quota.lua new file mode 100644 index 0000000000000000000000000000000000000000..abf49a31d4ace4ac46e21e77900914a01f966388 --- /dev/null +++ b/source/tools/monitor/unity/collector/container/cg_cpu_cfs_quota.lua @@ -0,0 +1,64 @@ +--- +--- Created by Hailong Liu. +--- DateTime: 2023/5/18 +--- + +require("common.class") +local unistd = require("posix.unistd") +local pystring = require("common.pystring") +local CvProc = require("collector.vproc") +local root = "sys/fs/cgroup/cpu/" +local quotFile = "/cpu.cfs_quota_us" +local periodFile = "/cpu.cfs_period_us" + +local CgCfsQuota = class("cg_cfs_quota", CvProc) + +--ls{}, (pod_name and docker_name +function CgCfsQuota:_init_(proto, pffi, mnt, path, ls) + CvProc._init_(self, proto, pffi, mnt, root .. path .. quotFile) + self.ls = ls + self.period = 0 + self.quota = 0 + self.nr_cpus = unistd.sysconf(84) + self.periodFp = mnt..root..path..periodFile +end + +function CgCfsQuota:proc(elapsed, lines) + -- if pFile not valid ,return -1 + local c = 1 + CvProc.proc(self) + local values = {} + + for line in io.lines(self.pFile) do + local cell = pystring:split(line) + self.quota = tonumber(cell[1]) + values[c] = { + name = "quota_us", + value = self.quota + } + c = c + 1 + end + + for line in io.lines(self.periodFp) do + local cell = pystring:split(line) + self.period = tonumber(cell[1]) + values[c] = { + name = "period_us", + value = self.period + } + c = c + 1 + end + local ratio = self.nr_cpus*100 + if self.quota ~= -1 then + ratio = self.quota*100.0/self.period + end + + values[c] = { + name = "quota_ratio", + value = ratio + } + self:appendLine(self:_packProto("cgCpuQuota", self.ls, values)) + self:push(lines) +end + +return CgCfsQuota diff --git a/source/tools/monitor/unity/collector/plugin.yaml b/source/tools/monitor/unity/collector/plugin.yaml index 8801cf35603b262fb6313c1f24c0b871185ba1fe..b9861be055e9011433785395da016d5a12ec55a4 100644 --- a/source/tools/monitor/unity/collector/plugin.yaml +++ b/source/tools/monitor/unity/collector/plugin.yaml @@ -29,7 +29,7 @@ container: #"cg_cpuacct_stat" is a substitute of cg_cpuacct_proc_stat luaPlugin: ["cg_cpu_stat", "cg_cpuacct_proc_stat", "cg_cpuacct_wait_latency", "cg_memory_dcmp_latency", "cg_memory_drcm_latency", "cg_memory_fail_cnt", "cg_memory_util", - "cg_pmu_events"] + "cg_pmu_events", "cg_cpu_cfs_quota"] directCgPath: - "/" - "/kubepods.slice" @@ -301,3 +301,8 @@ metrics: head: value help: "sysak_cg_cpu_stat" type: "gauge" + - title: sysak_cg_cpu_quota + from: cgCpuQuota + head: value + help: "quota_us,peroid_us and quota/period" + type: "gauge"