@cryptotaxi247 / netdata-1 / commits / 92bd9154a

Detect when swap is disabled when agent is running (#18702)

When swap is disabled while we collect it, mark it as obsolete

Stelios Fragkakis committed Oct 7, 2024 at 17:23 UTC 92bd9154a71fdda2c3c4f456d4693fca9f92b3a6
3 files changed +24 -4
src/collectors/common-contexts/mem-swap.h
+8
@@ -6,6 +6,14 @@ static inline void common_mem_swap(uint64_t free_bytes, uint64_t used_bytes, int
6 static RRDSET *st_system_swap = NULL;
7 static RRDDIM *rd_free = NULL, *rd_used = NULL;
8
9 + if (free_bytes == 0 && used_bytes == 0 && st_system_swap) {
10 + rrdset_is_obsolete___safe_from_collector_thread(st_system_swap);
11 + st_system_swap = NULL;
12 + rd_free = NULL;
13 + rd_used = NULL;
14 + return;
15 + }
16 +
17 if(unlikely(!st_system_swap)) {
18 st_system_swap = rrdset_create_localhost(
19 "mem"
src/collectors/proc.plugin/proc_meminfo.c
+9
@@ -12,6 +12,8 @@
12 int do_proc_meminfo(int update_every, usec_t dt) {
13 (void)dt;
14
15 + static bool swap_configured = false;
16 +
17 static procfile *ff = NULL;
18 static int do_ram = -1
19 , do_swap = -1
@@ -257,6 +259,7 @@ int do_proc_meminfo(int update_every, usec_t dt) {
259 if (SwapTotal && (do_swap == CONFIG_BOOLEAN_YES || do_swap == CONFIG_BOOLEAN_AUTO)) {
260 do_swap = CONFIG_BOOLEAN_YES;
261 common_mem_swap(SwapFree * 1024, SwapUsed * 1024, update_every);
262 + swap_configured = true;
263
264 {
265 static RRDSET *st_mem_swap_cached = NULL;
@@ -313,8 +316,14 @@ int do_proc_meminfo(int update_every, usec_t dt) {
316 rrddim_set_by_pointer(st_mem_zswap, rd_zswapped, Zswapped);
317 rrdset_done(st_mem_zswap);
318 }
319 + } else {
320 + if (swap_configured) {
321 + common_mem_swap(SwapFree * 1024, SwapUsed * 1024, update_every);
322 + swap_configured = false;
323 + }
324 }
325
326 +
327 if (arl_hwcorrupted->flags & ARL_ENTRY_FLAG_FOUND &&
328 (do_hwcorrupt == CONFIG_BOOLEAN_YES || do_hwcorrupt == CONFIG_BOOLEAN_AUTO)) {
329 do_hwcorrupt = CONFIG_BOOLEAN_YES;
src/health/health_event_loop.c
+7 -4
@@ -75,10 +75,13 @@ static inline int rrdcalc_isrunnable(RRDCALC *rc, time_t now, time_t *next_run)
75 time_t needed = now + rc->config.before + rc->config.after;
76
77 if(needed + update_every < first || needed - update_every > last) {
78 - netdata_log_debug(D_HEALTH
79 - , "Health not examining alarm '%s.%s' yet (not enough data yet - we need %lu but got %lu - %lu)."
80 - , rrdcalc_chart_name(rc), rrdcalc_name(rc), (unsigned long) needed, (unsigned long) first
81 - , (unsigned long) last);
78 + netdata_log_info(
79 + "Health not examining alarm '%s.%s' yet (not enough data yet - we need %lu but got %lu - %lu).",
80 + rrdcalc_chart_name(rc),
81 + rrdcalc_name(rc),
82 + (unsigned long) needed,
83 + (unsigned long) first,
84 + (unsigned long) last);
85 return 0;
86 }
87 }