From 5a8fc3fd598878eb5dc0de261144f784d5b60ede Mon Sep 17 00:00:00 2001 From: znzjugod Date: Wed, 16 Oct 2024 21:57:40 +0800 Subject: [PATCH] fix ebpf iodump warning --- .../src/c/ebpf_collector/ebpf_collector.c | 27 +++++++++---------- .../src/python/sentryCollector/collect_io.py | 4 +-- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/sysSentry-1.0.2/src/c/ebpf_collector/ebpf_collector.c b/sysSentry-1.0.2/src/c/ebpf_collector/ebpf_collector.c index d9496c3..aa46dc5 100644 --- a/sysSentry-1.0.2/src/c/ebpf_collector/ebpf_collector.c +++ b/sysSentry-1.0.2/src/c/ebpf_collector/ebpf_collector.c @@ -119,23 +119,19 @@ char* find_device_name(dev_t dev) { static void update_io_dump(struct bpf_map *map_res, int *io_dump, int *map_size, char *stage) { struct time_range_io_count time_count; - u32 io_dump_key = 0, io_dump_next_key = 0; + u32 io_dump_key = 0; struct sysinfo info; sysinfo(&info); - - while (bpf_map_get_next_key(map_res, &io_dump_key, &io_dump_next_key) == 0) { - int err = bpf_map_lookup_elem(map_res, &io_dump_next_key, &time_count); - if (err < 0) { - fprintf(stderr, "failed to lookup %s io dump: %d\n", stage, err); - break; - } - if (io_dump_key == io_dump_next_key) { - break; + int count_time = 150; + u32 curr_time = info.uptime; + while (count_time >= 0) { + io_dump_key = curr_time - count_time; + int err = bpf_map_lookup_elem(map_res, &io_dump_key, &time_count); + if (err < 0) { + count_time -= 1; + continue; } - - io_dump_key = io_dump_next_key; - - if ((info.uptime - io_dump_key) >= 2) { + if ((curr_time - io_dump_key) >= 2) { int isempty = 1; for (int key = 0; key < map_size; key++) { if (time_count.count[key] > 0) { @@ -143,10 +139,11 @@ static void update_io_dump(struct bpf_map *map_res, int *io_dump, int *map_size, isempty = 0; } } - if (isempty || (info.uptime - io_dump_key) > IO_DUMP_THRESHOLD) { + if (isempty || (curr_time - io_dump_key) > IO_DUMP_THRESHOLD) { bpf_map_delete_elem(map_res, &io_dump_key); } } + count_time -= 1; } } diff --git a/sysSentry-1.0.2/src/python/sentryCollector/collect_io.py b/sysSentry-1.0.2/src/python/sentryCollector/collect_io.py index 3d98c50..8a82eab 100644 --- a/sysSentry-1.0.2/src/python/sentryCollector/collect_io.py +++ b/sysSentry-1.0.2/src/python/sentryCollector/collect_io.py @@ -387,7 +387,7 @@ class CollectIo(): curr_io_dump_count: int, prev_io_dump_count: int ) -> Union[int, float]: - io_dump_count = curr_io_dump_count - prev_io_dump_count + io_dump_count = curr_io_dump_count if io_dump_count <= 0: return 0 value = io_dump_count @@ -466,4 +466,4 @@ class CollectIo(): # set stop event, notify thread exit def stop_thread(self): - self.stop_event.set() \ No newline at end of file + self.stop_event.set() -- Gitee