From b28549de4c37bb3034aec13deaea1ef56384ac33 Mon Sep 17 00:00:00 2001 From: yinbinbin Date: Thu, 12 May 2022 16:27:27 +0800 Subject: [PATCH 1/2] memgraph: fix json create failed Signed-off-by: yinbinbin --- source/tools/detect/memgraph/memgraph.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/tools/detect/memgraph/memgraph.py b/source/tools/detect/memgraph/memgraph.py index 0dba3e3c..5f865208 100644 --- a/source/tools/detect/memgraph/memgraph.py +++ b/source/tools/detect/memgraph/memgraph.py @@ -198,6 +198,8 @@ def memgraph_get_meminfo(meminfo): def dump2json(res,filename): jsonStr = json.dumps(res) + if not os.path.exists(os.path.dirname(filename)): + os.popen("mkdir -p "+os.path.dirname(filename)).read() with open(filename, 'w') as jsonFile: jsonFile.write(jsonStr) -- Gitee From 2439b711e2493d4df82970896131e7c438fcf3cf Mon Sep 17 00:00:00 2001 From: yinbinbin Date: Mon, 16 May 2022 23:13:31 +0800 Subject: [PATCH 2/2] oomcheck:get PodName/containerID Signed-off-by: yinbinbin --- source/tools/detect/oomcheck/oomcheck.py | 39 +++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/source/tools/detect/oomcheck/oomcheck.py b/source/tools/detect/oomcheck/oomcheck.py index 28f4bae6..3b54fd5a 100644 --- a/source/tools/detect/oomcheck/oomcheck.py +++ b/source/tools/detect/oomcheck/oomcheck.py @@ -175,7 +175,8 @@ def oom_get_cgroup_shmem(oom_result, line, num): inanon = line.strip().split("inactive_anon:")[1] inanon = inanon.split()[0][:-2] - anon = line.strip().split("active_anon:")[1] + anon = line.strip().split("inactive_anon:")[1] + anon = anon.strip().split("active_anon:")[1] anon = anon.split()[0][:-2] rss = line.strip().split("rss:")[1] @@ -333,6 +334,41 @@ def oom_check_score(oom, oom_result): else: return ',%d个进程%s累加消耗内存%dKB,oom_score_adj:%s. 另需进一步确认进程oom score设置是否合理.'%(res_total['cnt'],res_total['task'],res_total['rss']*4,res_total['score']) +def oom_get_podName(cgName, cID): + podName = 'unknow' + if cgName.find("kubepods") == -1: + return "unknow" + cmd = "crictl inspect " + cID + " | grep -w io.kubernetes.pod.name " + res = os.popen(cmd).read().strip() + if res.find("io.kubernetes.pod.name") == -1: + return 'unknow' + res = res.split() + if len(res) < 2: + return 'unkonw' + if res[0].find("io.kubernetes.pod.name") != -1: + podName = res[1][1:-2] + return podName + +def oom_get_k8spod(oom_result,num): + oom = oom_result['sub_msg'][num] + cgName = oom['cg_name'] + oom['podName'] = 'unknow' + oom['containerID '] = 'unknow' + index = cgName.find("cri-containerd-") + if index != -1: + index = index + 15 + if index == -1: + index = cgName.find("docker-") + if index != -1: + index = index + 7 + if index == -1: + return '' + oom['containerID '] = cgName[index: index+13] + oom['podName'] = oom_get_podName(cgName, oom['containerID ']) + summary = '' + summary += "podName: %s, containerID: %s\n"%(oom['podName'], oom['containerID ']) + return summary + def oom_output_msg(oom_result,num): oom = oom_result['sub_msg'][num] summary = '' @@ -343,6 +379,7 @@ def oom_output_msg(oom_result,num): summary += "进程所属cgroup:%s,"%(oom['cg_name']) if oom['cg_name'] in oom_result['cgroup']: summary += "cgroup OOM总次数:%s\n"%(oom_result['cgroup'][oom['cg_name']]) + summary += oom_get_k8spod(oom_result, num) summary += oom_cgroup_output(oom_result, num) summary += oom_host_output(oom_result, num) summary += "诊断结论:%s"%(oom['reason']) -- Gitee