From: Peter van Dijk Date: Mon, 25 Mar 2013 09:23:34 +0000 (+0000) Subject: add rec_control dump-nsspeeds X-Git-Tag: rec-3.5-rc3~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a82ce718b55f7d7fda3914b8bbfa1ba28ae008fc;p=pdns add rec_control dump-nsspeeds git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@3131 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 8ba94df43..8afa9356e 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -150,6 +150,33 @@ static uint64_t* pleaseDump(int fd) return new uint64_t(t_RC->doDump(fd) + dumpNegCache(t_sstorage->negcache, fd)); } +static uint64_t* pleaseDumpNSSpeeds(int fd) +{ + return new uint64_t(t_RC->doDumpNSSpeeds(fd)); +} + +template +string doDumpNSSpeeds(T begin, T end) +{ + T i=begin; + string fname; + + if(i!=end) + fname=*i; + + int fd=open(fname.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0660); + if(fd < 0) + return "Error opening dump file for writing: "+string(strerror(errno))+"\n"; + uint64_t total = 0; + try { + total = broadcastAccFunction(boost::bind(pleaseDumpNSSpeeds, fd)); + } + catch(...){} + + close(fd); + return "dumped "+lexical_cast(total)+" records\n"; +} + template string doDumpCache(T begin, T end) { @@ -565,6 +592,7 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP "current-queries show currently active queries\n" "dump-cache dump cache contents to the named file\n" "dump-edns[status] dump EDNS status to the named file\n" +"dump-nsspeeds dump nsspeeds statistics to the named file\n" "get [key1] [key2] .. get specific statistics\n" "get-all get all statistics\n" "get-parameter [key1] [key2] .. get configuration parameters\n" @@ -589,7 +617,6 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP if(cmd=="get-parameter") return doGetParameter(begin, end); - if(cmd=="quit") { *command=&doExit; return "bye\n"; @@ -606,6 +633,9 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP if(cmd=="dump-ednsstatus" || cmd=="dump-edns") return doDumpEDNSStatus(begin, end); + if(cmd=="dump-nsspeeds") + return doDumpNSSpeeds(begin, end); + if(cmd=="wipe-cache" || cmd=="flushname") return doWipeCache(begin, end); diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index 5110387d8..e1b23c3eb 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -345,6 +345,28 @@ bool MemRecursorCache::doAgeCache(time_t now, const string& name, uint16_t qtype return false; } +uint64_t MemRecursorCache::doDumpNSSpeeds(int fd) +{ + FILE* fp=fdopen(dup(fd), "w"); + if(!fp) + return 0; + fprintf(fp, "; nsspeed dump from thread follows\n;\n"); + uint64_t count=0; + + for(SyncRes::nsspeeds_t::iterator i = t_sstorage->nsSpeeds.begin() ; i!= t_sstorage->nsSpeeds.end(); ++i) + { + count++; + fprintf(fp, "%s|%d -> ", i->first.first.c_str(), i->first.second); + for(SyncRes::DecayingEwmaCollection::collection_t::iterator j = i->second.d_collection.begin(); j!= i->second.d_collection.end(); ++j) + { + // typedef vector > collection_t; + fprintf(fp, "%s/%f ", j->first.toString().c_str(), j->second.peek()); + } + fprintf(fp, "\n"); + } + fclose(fp); + return count; +} uint64_t MemRecursorCache::doDump(int fd) { diff --git a/pdns/recursor_cache.hh b/pdns/recursor_cache.hh index 4c4d73807..6d2b98596 100644 --- a/pdns/recursor_cache.hh +++ b/pdns/recursor_cache.hh @@ -38,6 +38,8 @@ public: void doPrune(void); void doSlash(int perc); uint64_t doDump(int fd); + uint64_t doDumpNSSpeeds(int fd); + int doWipeCache(const string& name, uint16_t qtype=0xffff); bool doAgeCache(time_t now, const string& name, uint16_t qtype, int32_t newTTL); uint64_t cacheHits, cacheMisses; diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 66825368c..0204bfd4a 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -156,6 +156,11 @@ public: return d_val*=factor; } + double peek(void) + { + return d_val; + } + bool stale(time_t limit) const { return limit > d_lastget.tv_sec;