]> arthur.barton.de Git - netdata.git/blobdiff - src/backends.c
allow each netdata host to have its own thread for streaming metrics
[netdata.git] / src / backends.c
index 30fba7fef6c7bbc8f7fde1e3b817e88b7ac2dfa5..c5b57dbe7ef291022d2e7d86ae558eaa96fae672 100644 (file)
@@ -147,11 +147,6 @@ void *backends_main(void *ptr) {
     // ------------------------------------------------------------------------
     // collect configuration options
 
-    if(central_netdata_to_push_data) {
-        info("Backend is disabled - use the central netdata");
-        goto cleanup;
-    }
-
     struct timeval timeout = {
             .tv_sec = 0,
             .tv_usec = 0
@@ -309,31 +304,28 @@ void *backends_main(void *ptr) {
         if(unlikely(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &pthreadoldcancelstate) != 0))
             error("Cannot set pthread cancel state to DISABLE.");
 
+        rrd_rdlock();
         RRDHOST *host;
-        for(host = localhost; host ; host = host->next) {
-            // for each host
+        rrdhost_foreach_read(host) {
+            if(host->rrd_memory_mode == RRD_MEMORY_MODE_NONE)
+                continue;
 
             rrdhost_rdlock(host);
 
             RRDSET *st;
-            for(st = host->rrdset_root; st; st = st->next) {
-                // for each chart
-
+            rrdset_foreach_read(st, host) {
                 rrdset_rdlock(st);
 
                 RRDDIM *rd;
-                for(rd = st->dimensions; rd; rd = rd->next) {
-                    // for each dimension
-
+                rrddim_foreach_read(rd, st) {
                     if(rd->last_collected_time.tv_sec >= after)
                         chart_buffered_metrics += backend_request_formatter(b, prefix, host, (host == localhost)?hostname:host->hostname, st, rd, after, before, options);
                 }
-
                 rrdset_unlock(st);
             }
-
             rrdhost_unlock(host);
         }
+        rrd_unlock();
 
         if(unlikely(pthread_setcancelstate(pthreadoldcancelstate, NULL) != 0))
             error("Cannot set pthread cancel state to RESTORE (%d).", pthreadoldcancelstate);
@@ -405,7 +397,7 @@ void *backends_main(void *ptr) {
             usec_t start_ut = now_monotonic_usec();
             size_t reconnects = 0;
 
-            sock = connect_to_one_of(destination, default_port, &timeout, &reconnects);
+            sock = connect_to_one_of(destination, default_port, &timeout, &reconnects, NULL, 0);
 
             chart_backend_reconnects += reconnects;
             chart_backend_latency += now_monotonic_usec() - start_ut;