]> granicus.if.org Git - pdns/commitdiff
add rec_control dump-nsspeeds
authorPeter van Dijk <peter.van.dijk@netherlabs.nl>
Mon, 25 Mar 2013 09:23:34 +0000 (09:23 +0000)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Mon, 25 Mar 2013 09:23:34 +0000 (09:23 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@3131 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/rec_channel_rec.cc
pdns/recursor_cache.cc
pdns/recursor_cache.hh
pdns/syncres.hh

index 8ba94df430a49c346406f5656107b88a4c764103..8afa9356e7ab58766f2e6dc038542f95e724a52c 100644 (file)
@@ -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<typename T>
+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<uint64_t>(boost::bind(pleaseDumpNSSpeeds, fd));
+  }
+  catch(...){}
+
+  close(fd);
+  return "dumped "+lexical_cast<string>(total)+" records\n";
+}
+
 template<typename T>
 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 <filename>            dump cache contents to the named file\n"
 "dump-edns[status] <filename>     dump EDNS status to the named file\n"
+"dump-nsspeeds <filename>         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);
 
index 5110387d890f70a898692f519e6cc9c17f0fbc65..e1b23c3eb493f0625ab174cea2e0b970a83e0ee3 100644 (file)
@@ -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<pair<ComboAddress, DecayingEwma> > 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)
 {
index 4c4d73807d601a14080be9412301bcdb05dee955..6d2b98596d20bbd350b8e842dc5e9e213c0218c4 100644 (file)
@@ -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;
index 66825368c86a960596f97187d224ca6249ec0974..0204bfd4a250e9522b3cda871ee72f07f7d5bee2 100644 (file)
@@ -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;