]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
expand 'carbon-server' to also support multiple , separated servers for recursor... 3485/head
authorbert hubert <bert.hubert@netherlabs.nl>
Sat, 27 Feb 2016 13:01:31 +0000 (14:01 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sat, 27 Feb 2016 13:01:31 +0000 (14:01 +0100)
pdns/rec-carbon.cc

index fbc776dbe4ae7800a61b13d4b7173a29151e1c36..7da9a788ee54a59d91fd111d0ff1cec52eae8bf9 100644 (file)
 void doCarbonDump(void*)
 try
 {
-  string hostname, carbonServer;
+  string hostname;
+  vector<string> carbonServers;
 
   {
     Lock l(&g_carbon_config_lock);
-    carbonServer=arg()["carbon-server"];
+    stringtok(carbonServers, arg()["carbon-server"], ", ");
     hostname=arg()["carbon-ourname"];
   }
 
-  if(carbonServer.empty())
+  if(carbonServers.empty())
     return;
 
-  RecursorControlParser rcp; // inits if needed
-  ComboAddress remote(carbonServer, 2003);
-  Socket s(remote.sin4.sin_family, SOCK_STREAM);
-
-  s.setNonBlocking();
-  s.connect(remote);  // we do the connect so the attempt happens while we gather stats
-  typedef map<string,string> all_t;
-  all_t all=getAllStatsMap();
-
-  ostringstream str;
-  time_t now=time(0);
-
   if(hostname.empty()) {
     char tmp[80];
     memset(tmp, 0, sizeof(tmp));
@@ -47,16 +35,35 @@ try
     hostname=tmp;
     boost::replace_all(hostname, ".", "_");    
   }
-  for(const all_t::value_type& val :  all) {
-    str<<"pdns."<<hostname<<".recursor."<<val.first<<' '<<val.second<<' '<<now<<"\r\n";
-  }
-  const string msg = str.str();
 
-  int ret=asendtcp(msg, &s);     // this will actually do the right thing waiting on the connect
-  if(ret < 0)
-    L<<Logger::Warning<<"Error writing carbon data to "<<remote.toStringWithPort()<<": "<<strerror(errno)<<endl;
-  if(ret==0)
-    L<<Logger::Warning<<"Timeout connecting/writing carbon data to "<<remote.toStringWithPort()<<endl;
+  string msg;
+  for(const auto& carbonServer: carbonServers) {
+    RecursorControlParser rcp; // inits if needed
+    ComboAddress remote(carbonServer, 2003);
+    Socket s(remote.sin4.sin_family, SOCK_STREAM);
+
+    s.setNonBlocking();
+    s.connect(remote);  // we do the connect so the first attempt happens while we gather stats
+    if(msg.empty()) {
+      typedef map<string,string> all_t;
+      all_t all=getAllStatsMap();
+      
+      ostringstream str;
+      time_t now=time(0);
+      
+      for(const all_t::value_type& val :  all) {
+        str<<"pdns."<<hostname<<".recursor."<<val.first<<' '<<val.second<<' '<<now<<"\r\n";
+      }
+      msg = str.str();
+    }
+
+    int ret=asendtcp(msg, &s);     // this will actually do the right thing waiting on the connect
+    if(ret < 0)
+      L<<Logger::Warning<<"Error writing carbon data to "<<remote.toStringWithPort()<<": "<<strerror(errno)<<endl;
+    if(ret==0)
+      L<<Logger::Warning<<"Timeout connecting/writing carbon data to "<<remote.toStringWithPort()<<endl;
+  }
  }
 catch(PDNSException& e)
 {