summaryrefslogtreecommitdiffstats
path: root/health/health.c
diff options
context:
space:
mode:
authorvkalintiris <vasilis@netdata.cloud>2022-03-31 17:49:44 +0300
committerGitHub <noreply@github.com>2022-03-31 17:49:44 +0300
commitaf72ed83f929b312a254b9e8b9b74c7403b689ac (patch)
treed59b96e5df4aa40f2404a23b32ebab650e4dcb84 /health/health.c
parent18428d6c27cf2701f40669d640666db5b953e0e0 (diff)
Initialize foreach alarms of dimensions in health thread. (#12452)
The previous approach required us to try wr-lock the host after locking a chart and sleeping on failure. Lock contention would lead to alarms not being created and the agent to become unresponsive.
Diffstat (limited to 'health/health.c')
-rw-r--r--health/health.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/health/health.c b/health/health.c
index f29d07c2fd..9916b43382 100644
--- a/health/health.c
+++ b/health/health.c
@@ -655,6 +655,41 @@ static int update_disabled_silenced(RRDHOST *host, RRDCALC *rc) {
return 0;
}
+// Create alarms for dimensions that have been added to charts
+// since the previous iteration.
+static void init_pending_foreach_alarms(RRDHOST *host) {
+ rrdhost_wrlock(host);
+
+ if (host->alarms_with_foreach || host->alarms_template_with_foreach) {
+ if (rrdhost_flag_check(host, RRDHOST_FLAG_PENDING_FOREACH_ALARMS)) {
+ RRDSET *st;
+
+ rrdset_foreach_read(st, host) {
+ rrdset_wrlock(st);
+
+ if (rrdset_flag_check(st, RRDSET_FLAG_PENDING_FOREACH_ALARMS)) {
+ RRDDIM *rd;
+
+ rrddim_foreach_write(rd, st) {
+ if (rrddim_flag_check(rd, RRDDIM_FLAG_PENDING_FOREACH_ALARM)) {
+ rrdcalc_link_to_rrddim(rd, st, host);
+ rrddim_flag_clear(rd, RRDDIM_FLAG_PENDING_FOREACH_ALARM);
+ }
+ }
+
+ rrdset_flag_clear(st, RRDSET_FLAG_PENDING_FOREACH_ALARMS);
+ }
+
+ rrdset_unlock(st);
+ }
+
+ rrdhost_flag_clear(host, RRDHOST_FLAG_PENDING_FOREACH_ALARMS);
+ }
+ }
+
+ rrdhost_unlock(host);
+}
+
/**
* Health Main
*
@@ -739,6 +774,8 @@ void *health_main(void *ptr) {
if(likely(!host->health_log_fp) && (loop == 1 || loop % cleanup_sql_every_loop == 0))
sql_health_alarm_log_cleanup(host);
+ init_pending_foreach_alarms(host);
+
rrdhost_rdlock(host);
// the first loop is to lookup values from the db