]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
enable configuration of carbon/metronome telemetry at runtime for painless debugging
authorbert hubert <bert.hubert@netherlabs.nl>
Fri, 29 Aug 2014 15:22:27 +0000 (17:22 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Fri, 29 Aug 2014 15:22:27 +0000 (17:22 +0200)
pdns/arguments.cc
pdns/rec-carbon.cc
pdns/rec_channel.hh
pdns/rec_channel_rec.cc

index e5abcdb83419069701c09a20ee656d1affc92c17..163537dbe5a94784f559dad99b123355eb7218e7 100644 (file)
@@ -170,13 +170,11 @@ string ArgvMap::configstring(bool current)
   return help;
 }
 
-
 const string & ArgvMap::operator[](const string &arg)
 {
   if(!parmIsset(arg))
     throw ArgException(string("Undefined but needed argument: '")+arg+"'");
 
-
   return params[arg];
 }
 
index 685958003f2a373bf19eb6c5c6a640f9f70df836..1029e20113c75f614f3df4c2a8b01d2521b90c4f 100644 (file)
@@ -4,16 +4,25 @@
 #include "iputils.hh"
 #include "logger.hh"
 #include "arguments.hh"
+#include "lock.hh"
 #include <boost/foreach.hpp>
 
 void doCarbonDump(void*)
 try
 {
-  if(arg()["carbon-server"].empty())
+  string hostname, carbonServer;
+
+  {
+    Lock l(&g_carbon_config_lock);
+    carbonServer=arg()["carbon-server"];
+    hostname=arg()["carbon-ourname"];
+  }
+
+  if(carbonServer.empty())
     return;
 
   RecursorControlParser rcp; // inits if needed
-  ComboAddress remote(arg()["carbon-server"], 2003);
+  ComboAddress remote(carbonServer, 2003);
   Socket s(remote.sin4.sin_family, SOCK_STREAM);
 
   s.setNonBlocking();
@@ -24,7 +33,7 @@ try
 
   ostringstream str;
   time_t now=time(0);
-  string hostname=arg()["carbon-ourname"];
+
   if(hostname.empty()) {
     char tmp[80];
     memset(tmp, 0, sizeof(tmp));
index 7bd60240e8b5c8a7d7653dc773731a431ec98e2d..bb0a71d0fe793251250823ea660fe8aa410c5b35 100644 (file)
@@ -39,5 +39,5 @@ private:
 };
 
 std::map<std::string, std::string> getAllStatsMap();
-
+extern pthread_mutex_t g_carbon_config_lock;
 #endif 
index d1444658d3ab1d80c7ed97bf77b81aaa482f6f70..d719140dbe3c212d093f36dc3d81e23f1e66289c 100644 (file)
@@ -23,6 +23,7 @@
 #include "responsestats.hh"
 
 #include "namespaces.hh"
+pthread_mutex_t g_carbon_config_lock=PTHREAD_MUTEX_INITIALIZER;
 
 map<string, const uint32_t*> d_get32bitpointers;
 map<string, const uint64_t*> d_get64bitpointers;
@@ -246,6 +247,26 @@ string doWipeCache(T begin, T end)
   return "wiped "+lexical_cast<string>(count)+" records, "+lexical_cast<string>(countNeg)+" negative records\n";
 }
 
+template<typename T>
+string doSetCarbonServer(T begin, T end)
+{
+  Lock l(&g_carbon_config_lock);
+  if(begin==end) {
+    ::arg().set("carbon-server").clear();
+    return "cleared carbon-server setting\n";
+  }
+  string ret;
+  ::arg().set("carbon-server")=*begin;
+  ret="set carbon-server to '"+::arg()["carbon-server"]+"'\n";
+  if(begin != end) {
+    ++begin;
+    ::arg().set("carbon-ourname")=*begin;
+    ret+="set carbon-ourname to '"+*begin+"'\n";
+  }
+  return ret;
+}
+
+
 template<typename T>
 string setMinimumTTL(T begin, T end)
 {
@@ -638,6 +659,7 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP
 "reload-lua-script [filename]     (re)load Lua script\n"
 "reload-zones                     reload all auth and forward zones\n"
 "set-minimum-ttl value            set mininum-ttl-override\n"
+"set-carbon-server                set a carbon server for telemetry\n"
 "trace-regex [regex]              emit resolution trace for matching queries (empty regex to clear trace)\n"
 "top-remotes                      show top remotes\n"
 "unload-lua-script                unload Lua script\n"
@@ -677,6 +699,9 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP
   if(cmd=="reload-lua-script") 
     return doQueueReloadLuaScript(begin, end);
 
+  if(cmd=="set-carbon-server") 
+    return doSetCarbonServer(begin, end);
+
   if(cmd=="trace-regex") 
     return doTraceRegex(begin, end);