From 77a6fa666fa991ff778d5ccad628a263be6cd302 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Fri, 29 Aug 2014 17:22:27 +0200 Subject: [PATCH] enable configuration of carbon/metronome telemetry at runtime for painless debugging --- pdns/arguments.cc | 2 -- pdns/rec-carbon.cc | 15 ++++++++++++--- pdns/rec_channel.hh | 2 +- pdns/rec_channel_rec.cc | 25 +++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/pdns/arguments.cc b/pdns/arguments.cc index e5abcdb834..163537dbe5 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -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]; } diff --git a/pdns/rec-carbon.cc b/pdns/rec-carbon.cc index 685958003f..1029e20113 100644 --- a/pdns/rec-carbon.cc +++ b/pdns/rec-carbon.cc @@ -4,16 +4,25 @@ #include "iputils.hh" #include "logger.hh" #include "arguments.hh" +#include "lock.hh" #include 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)); diff --git a/pdns/rec_channel.hh b/pdns/rec_channel.hh index 7bd60240e8..bb0a71d0fe 100644 --- a/pdns/rec_channel.hh +++ b/pdns/rec_channel.hh @@ -39,5 +39,5 @@ private: }; std::map getAllStatsMap(); - +extern pthread_mutex_t g_carbon_config_lock; #endif diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index d1444658d3..d719140dbe 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -23,6 +23,7 @@ #include "responsestats.hh" #include "namespaces.hh" +pthread_mutex_t g_carbon_config_lock=PTHREAD_MUTEX_INITIALIZER; map d_get32bitpointers; map d_get64bitpointers; @@ -246,6 +247,26 @@ string doWipeCache(T begin, T end) return "wiped "+lexical_cast(count)+" records, "+lexical_cast(countNeg)+" negative records\n"; } +template +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 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); -- 2.47.2