]> arthur.barton.de Git - netdata.git/blobdiff - src/health.c
unified rrd locks
[netdata.git] / src / health.c
index 0ef6f718bcbe48f364878bb58b0bbd964b3875c8..bd62fbcf8b7fbb8d3ead594422b15df7a61909d4 100644 (file)
@@ -3,7 +3,7 @@
 
 #define RRDVAR_MAX_LENGTH 1024
 
-int health_enabled = 1;
+int default_localhost_health_enabled = 1;
 
 // ----------------------------------------------------------------------------
 // RRDVAR management
@@ -1075,7 +1075,7 @@ inline char *health_config_dir(void) {
 void health_init(void) {
     debug(D_HEALTH, "Health configuration initializing");
 
-    if(!(health_enabled = config_get_boolean("health", "enabled", 1))) {
+    if(!(default_localhost_health_enabled = config_get_boolean("health", "enabled", 1))) {
         debug(D_HEALTH, "Health is disabled.");
         return;
     }
@@ -1098,15 +1098,10 @@ inline void health_free_host_nolock(RRDHOST *host) {
 }
 
 void health_reload_host(RRDHOST *host) {
-    if(!health_enabled) {
-        error("Health reload is requested, but health is not enabled.");
-        return;
-    }
-
     char *path = health_config_dir();
 
     // free all running alarms
-    rrdhost_rwlock(host);
+    rrdhost_wrlock(host);
     health_free_host_nolock(host);
     rrdhost_unlock(host);
 
@@ -1125,13 +1120,13 @@ void health_reload_host(RRDHOST *host) {
     }
 
     // load the new alarms
-    rrdhost_rwlock(host);
+    rrdhost_wrlock(host);
     health_readdir(host, path);
     rrdhost_unlock(host);
 
     // link the loaded alarms to their charts
     for(st = host->rrdset_root; st ; st = st->next) {
-        rrdhost_rwlock(host);
+        rrdhost_wrlock(host);
 
         rrdsetcalc_link_matching(st);
         rrdcalctemplate_link_matching(st);
@@ -1406,7 +1401,7 @@ void *health_main(void *ptr) {
     BUFFER *wb = buffer_create(100);
 
     unsigned int loop = 0;
-    while(health_enabled && !netdata_exit) {
+    while(!netdata_exit) {
         loop++;
         debug(D_HEALTH, "Health monitoring iteration no %u started", loop);
 
@@ -1420,6 +1415,8 @@ void *health_main(void *ptr) {
 
         RRDHOST *host;
         for(host = localhost; host ; host = host->next) {
+            if(unlikely(!host->health_enabled)) continue;
+
             rrdhost_rdlock(host);
 
             // the first loop is to lookup values from the db