gala-gopher/bugfix-fix-system_proc-collect-data-err.patch
xietangxin 71cf797faf sync bugfix patch from openeuler/gala-gopher
(cherry picked from commit 4ea8a981b29acd853dd2d279d658055e0e6e79a1)
2023-04-10 10:53:07 +08:00

164 lines
6.5 KiB
Diff

From 3bc3d1d20a220ab3a0a9093059289cc841bd45e2 Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Mon, 27 Mar 2023 11:38:26 +0800
Subject: [PATCH 26/30] bugfix: fix system_proc collect data err
---
src/daemon/daemon.c | 2 +-
.../ebpf.probe/src/lvsprobe/trace_lvs.bpf.c | 2 +-
.../cadvisor.probe/cadvisor_probe.py | 4 ++++
src/probes/system_infos.probe/system_net.c | 4 ++--
src/probes/system_infos.probe/system_procs.c | 18 +++++++++++++-----
src/probes/system_infos.probe/system_procs.h | 11 +----------
6 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index f3ab821..b10ca60 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -26,7 +26,7 @@
#include "daemon.h"
#include "object.h"
-#define RM_MAP_CMD "/usr/bin/find %s/* | /usr/bin/grep -v '%s\\|%s\\|%s' | /usr/bin/xargs rm -f"
+#define RM_MAP_CMD "/usr/bin/find %s/* 2> /dev/null | /usr/bin/grep -v '%s\\|%s\\|%s' | /usr/bin/xargs rm -f"
static const ResourceMgr *resouce_msg;
#if GALA_GOPHER_INFO("inner func declaration")
diff --git a/src/probes/extends/ebpf.probe/src/lvsprobe/trace_lvs.bpf.c b/src/probes/extends/ebpf.probe/src/lvsprobe/trace_lvs.bpf.c
index cc2747c..ceb6548 100644
--- a/src/probes/extends/ebpf.probe/src/lvsprobe/trace_lvs.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/lvsprobe/trace_lvs.bpf.c
@@ -187,7 +187,7 @@ KPROBE(ip_vs_conn_expire, pt_regs)
value_p = bpf_map_lookup_elem(&lvs_link_map, &key);
if (value_p == (void *)0) {
bpf_printk("===LVS ubind dest not in hash map.\n");
- return;
+ return 0;
}
value_p->state = IP_VS_TCP_S_CLOSE;
value_p->close_ts = bpf_ktime_get_ns();
diff --git a/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py b/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
index 65db0f5..8b65117 100644
--- a/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
+++ b/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
@@ -200,6 +200,10 @@ class BasicLabelProbe(Probe):
self.container_lib.get_all_container.restype = POINTER(ContainerTbl)
tbl_p = self.container_lib.get_all_container()
+ if not tbl_p:
+ print("[cadvisor_probe] no active containers in system")
+ return 0
+
for i in range(tbl_p.contents.num):
if tbl_p.contents.cs[i].status != CONTAINER_STATUS_RUNNING:
continue
diff --git a/src/probes/system_infos.probe/system_net.c b/src/probes/system_infos.probe/system_net.c
index 0962a9b..ce5cc04 100644
--- a/src/probes/system_infos.probe/system_net.c
+++ b/src/probes/system_infos.probe/system_net.c
@@ -99,7 +99,7 @@ int system_tcp_probe(void)
/* output */
(void)nprobe_fprintf(stdout, "|%s|%s|%llu|%llu|%llu|%llu|%llu|\n",
METRICS_TCP_NAME,
- "/proc/dev/snmp",
+ "/proc/net/snmp",
g_snmp_stats.tcp_curr_estab,
(g_snmp_stats.tcp_in_segs > temp.tcp_in_segs) ? (g_snmp_stats.tcp_in_segs - temp.tcp_in_segs) : 0,
(g_snmp_stats.tcp_out_segs > temp.tcp_out_segs) ? (g_snmp_stats.tcp_out_segs - temp.tcp_out_segs) : 0,
@@ -109,7 +109,7 @@ int system_tcp_probe(void)
(void)nprobe_fprintf(stdout, "|%s|%s|%llu|%llu|\n",
METRICS_UDP_NAME,
- "/proc/dev/snmp",
+ "/proc/net/snmp",
(g_snmp_stats.udp_in_datagrams > temp.udp_in_datagrams) ?
(g_snmp_stats.udp_in_datagrams - temp.udp_in_datagrams) : 0,
(g_snmp_stats.udp_out_datagrams > temp.udp_out_datagrams) ?
diff --git a/src/probes/system_infos.probe/system_procs.c b/src/probes/system_infos.probe/system_procs.c
index d2d3c9a..1c32f53 100644
--- a/src/probes/system_infos.probe/system_procs.c
+++ b/src/probes/system_infos.probe/system_procs.c
@@ -27,7 +27,7 @@
#define PROC_STAT "/proc/%s/stat"
#define PROC_START_TIME_CMD "/usr/bin/cat /proc/%s/stat | awk '{print $22}'"
#define PROC_FD "/proc/%s/fd"
-#define PROC_FD_CNT_CMD "/usr/bin/ls -l /proc/%s/fd 2>/dev/null | wc -l 2>/dev/null"
+#define PROC_FD_CNT_CMD "/usr/bin/ls /proc/%s/fd 2>/dev/null | wc -l 2>/dev/null"
#define PROC_IO "/proc/%s/io"
#define PROC_IO_CMD "/usr/bin/cat /proc/%s/io"
#define PROC_SMAPS "/proc/%s/smaps_rollup"
@@ -459,6 +459,10 @@ static int get_proc_mss(const char *pid, proc_info_t *proc_info)
u32 value = 0;
char fname_or_cmd[LINE_BUF_LEN];
char line[LINE_BUF_LEN];
+ char key[LINE_BUF_LEN];
+ char smap_key_list[PROC_MSS_MAX][LINE_BUF_LEN] = {"Shared_Clean:", "Shared_Dirty:", "Private_Clean:",
+ "Private_Dirty:", "Referenced:", "LazyFree:", "Swap:", "SwapPss:"};
+ int smap_index = 0;
fname_or_cmd[0] = 0;
(void)snprintf(fname_or_cmd, LINE_BUF_LEN, PROC_SMAPS, pid);
@@ -471,8 +475,9 @@ static int get_proc_mss(const char *pid, proc_info_t *proc_info)
if (f == NULL) {
goto out;
}
- while (!feof(f) && (index < PROC_MSS_MAX)) {
+ while (!feof(f)) {
line[0] = 0;
+ key[0] = 0;
if (fgets(line, LINE_BUF_LEN, f) == NULL) {
goto out;
}
@@ -481,12 +486,15 @@ static int get_proc_mss(const char *pid, proc_info_t *proc_info)
continue;
}
value = 0;
- int ret = sscanf(line, "%*s %lu %*s", &value);
+ int ret = sscanf(line, "%s %lu %*s", key, &value);
if (ret < 1) {
goto out;
}
- do_set_proc_mss(proc_info, value, index);
- index++;
+ if (strcmp(smap_key_list[smap_index], key) != 0) {
+ continue;
+ }
+ do_set_proc_mss(proc_info, value, smap_index);
+ smap_index++;
}
out:
if (f != NULL) {
diff --git a/src/probes/system_infos.probe/system_procs.h b/src/probes/system_infos.probe/system_procs.h
index 9c9a77d..58cf4f8 100644
--- a/src/probes/system_infos.probe/system_procs.h
+++ b/src/probes/system_infos.probe/system_procs.h
@@ -50,23 +50,14 @@ enum proc_stat_e {
};
enum proc_mss_e {
- PROC_MSS_RESIDENT = 0,
- PROC_MSS_SHARED_CLEAN,
+ PROC_MSS_SHARED_CLEAN = 0,
PROC_MSS_SHARED_DIRTY,
PROC_MSS_PRIVATE_CLEAN,
PROC_MSS_PROVATE_DIRTY,
PROC_MSS_REFERENCED,
- PROC_MSS_ANONYMOUS,
PROC_MSS_LAZYFREE,
- PROC_MSS_ANONYMOUS_THP,
PROC_MSS_SWAP,
- PROC_MSS_SHARED_HUGETLB,
- PROC_MSS_PRIVATE_HUGETLB,
- PROC_MSS_PSS,
- PROC_MSS_PSS_LOCKED,
PROC_MSS_SWAP_PSS,
- PROC_MSS_CHECK_SHNEM_SWAP,
-
PROC_MSS_MAX
};
--
2.33.0