diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2022-11-10 18:37:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 18:37:10 +0200 |
commit | 4afc63c85d319c8965ab446af6d167f5e9eb3199 (patch) | |
tree | d5e063e50fc092baf093eb1b7aff1d9c8d45cee5 /health | |
parent | d62a168074b6771e0bb5de7a1c1ab2901a912be5 (diff) |
Remove health_thread_stop (#13948)
* remove health_thread_stop
* soft sleeps
Diffstat (limited to 'health')
-rw-r--r-- | health/health.c | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/health/health.c b/health/health.c index 87dddbfb6e..1b4f43cf36 100644 --- a/health/health.c +++ b/health/health.c @@ -601,20 +601,11 @@ static void health_thread_cleanup(void *ptr) { struct health_state *h = ptr; h->host->health_spawn = 0; - netdata_thread_detach(netdata_thread_self()); + netdata_thread_cancel(netdata_thread_self()); log_health("[%s]: Health thread ended.", rrdhost_hostname(h->host)); debug(D_HEALTH, "HEALTH %s: Health thread ended.", rrdhost_hostname(h->host)); } -void health_thread_stop(RRDHOST *host) { - if(host->health_spawn) { - log_health("[%s]: Signaling health thread to stop...", rrdhost_hostname(host)); - - // signal it to cancel - netdata_thread_cancel(host->health_thread); - } -} - static void initialize_health(RRDHOST *host, int is_localhost) { if(!host->health_enabled || rrdhost_flag_check(host, RRDHOST_FLAG_INITIALIZED_HEALTH)) return; rrdhost_flag_set(host, RRDHOST_FLAG_INITIALIZED_HEALTH); @@ -701,13 +692,15 @@ static void initialize_health(RRDHOST *host, int is_localhost) { health_silencers_init(); } -static void health_sleep(time_t next_run, unsigned int loop) { +static void health_sleep(time_t next_run, unsigned int loop, RRDHOST *host) { time_t now = now_realtime_sec(); if(now < next_run) { worker_is_idle(); debug(D_HEALTH, "Health monitoring iteration no %u done. Next iteration in %d secs", loop, (int) (next_run - now)); - sleep_usec(USEC_PER_SEC * (usec_t) (next_run - now)); - now = now_realtime_sec(); + while (now < next_run && host->health_enabled && !netdata_exit) { + sleep_usec(USEC_PER_SEC); + now = now_realtime_sec(); + } } else { debug(D_HEALTH, "Health monitoring iteration no %u done. Next iteration now", loop); @@ -886,7 +879,7 @@ void *health_main(void *ptr) { #ifdef ENABLE_ACLK unsigned int marked_aclk_reload_loop = 0; #endif - while(!netdata_exit) { + while(!netdata_exit && host->health_enabled) { loop++; debug(D_HEALTH, "Health monitoring iteration no %u started", loop); @@ -928,13 +921,13 @@ void *health_main(void *ptr) { host->health_delay_up_to = now + hibernation_delay; next_run = now + hibernation_delay; - health_sleep(next_run, loop); + health_sleep(next_run, loop, host); } if (unlikely(host->health_delay_up_to)) { if (unlikely(now < host->health_delay_up_to)) { next_run = host->health_delay_up_to; - health_sleep(next_run, loop); + health_sleep(next_run, loop, host); continue; } @@ -942,15 +935,11 @@ void *health_main(void *ptr) { host->health_delay_up_to = 0; } - if (unlikely(!host->health_enabled)) { - health_thread_stop(host); - } - // wait until cleanup of obsolete charts on children is complete if (host != localhost) { if (unlikely(host->trigger_chart_obsoletion_check == 1)) { log_health("[%s]: Waiting for chart obsoletion check.", rrdhost_hostname(host)); - health_sleep(next_run, loop); + health_sleep(next_run, loop, host); continue; } } @@ -1413,7 +1402,7 @@ void *health_main(void *ptr) { if(unlikely(netdata_exit)) break; - health_sleep(next_run, loop); + health_sleep(next_run, loop, host); } // forever |