]> arthur.barton.de Git - netdata.git/commitdiff
prevent remote hosts from taking the localhost position
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 24 Feb 2017 21:48:23 +0000 (23:48 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 24 Feb 2017 21:48:23 +0000 (23:48 +0200)
src/main.c
src/rrdhost.c
src/rrdpush.c

index 885e34b13f28ddedf86687514caea3bb44c8f26f..c602649d6c0e2b736a0cf4fb1aea388a139f28da 100644 (file)
@@ -902,6 +902,12 @@ int main(int argc, char **argv) {
     }
 
 
+    // ------------------------------------------------------------------------
+    // initialize rrd host
+
+    rrd_init(netdata_configured_hostname);
+
+
     // --------------------------------------------------------------------
     // find we need to send data to another netdata
 
@@ -920,12 +926,6 @@ int main(int argc, char **argv) {
     registry_init();
 
 
-    // ------------------------------------------------------------------------
-    // initialize rrd host
-
-    rrd_init(netdata_configured_hostname);
-
-
     if(check_config)
         exit(1);
 
index 5fc7b6b9195b0da679f29aaba96d63ff211f2316..ac6ed25ea76f4e316eca9554dd8c05bf663e2205 100644 (file)
@@ -64,7 +64,9 @@ RRDHOST *rrdhost_create(const char *hostname,
         int update_every,
         int entries,
         RRD_MEMORY_MODE memory_mode,
-        int health_enabled) {
+        int health_enabled,
+        int is_localhost
+) {
 
     debug(D_RRDHOST, "Host '%s': adding with guid '%s'", hostname, guid);
 
@@ -113,8 +115,7 @@ RRDHOST *rrdhost_create(const char *hostname,
 
     char filename[FILENAME_MAX + 1];
 
-    if(!localhost) {
-        // this is localhost
+    if(is_localhost) {
 
         host->cache_dir  = strdupz(netdata_configured_cache_dir);
         host->varlib_dir = strdupz(netdata_configured_varlib_dir);
@@ -174,9 +175,16 @@ RRDHOST *rrdhost_create(const char *hostname,
 
     rrd_wrlock();
 
-    if(localhost) {
-        host->next = localhost->next;
-        localhost->next = host;
+    if(is_localhost) {
+        host->next = localhost;
+        localhost = host;
+    }
+    else {
+        if(localhost) {
+            host->next = localhost->next;
+            localhost->next = host;
+        }
+        else localhost = host;
     }
 
     if(rrdhost_index_add(host) != host)
@@ -193,7 +201,7 @@ RRDHOST *rrdhost_find_or_create(const char *hostname, const char *guid, const ch
 
     RRDHOST *host = rrdhost_find(guid, 0);
     if(!host) {
-        host = rrdhost_create(hostname, guid, os, update_every, history, mode, health_enabled);
+        host = rrdhost_create(hostname, guid, os, update_every, history, mode, health_enabled, 0);
     }
     else {
         host->health_enabled = health_enabled;
@@ -230,7 +238,8 @@ void rrd_init(char *hostname) {
             default_rrd_update_every,
             default_rrd_history_entries,
             default_rrd_memory_mode,
-            default_health_enabled
+            default_health_enabled,
+            1
     );
 }
 
index c418e3278cf375ed3ff13fb8a99540326ec34cb8..f5e180630427d9550dea439f4f5fabdffe8492cf 100644 (file)
@@ -571,7 +571,7 @@ void rrdpush_sender_thread_spawn(RRDHOST *host) {
 
 int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url) {
     (void)host;
-    
+
     info("STREAM [receive from [%s]:%s]: new client connection.", w->client_ip, w->client_port);
 
     char *key = NULL, *hostname = NULL, *machine_guid = NULL, *os = NULL;