]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Added qtype statistics to recursor and rec_control (get-qtypelist)
authorFusl <root@hallowe.lt>
Tue, 21 Jan 2014 13:15:34 +0000 (14:15 +0100)
committerFusl <root@hallowe.lt>
Tue, 21 Jan 2014 13:15:34 +0000 (14:15 +0100)
pdns/Makefile.am
pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc
pdns/responsestats.cc

index cb8541f903f62e4160c01a07b8ec253260fd07d9..70372fd8f439ac6a6ff8c6463f6e8e56709e34fd 100644 (file)
@@ -281,7 +281,7 @@ rec_channel_rec.cc selectmplexer.cc epollmplexer.cc sillyrecords.cc htimer.cc ht
 dns_random.cc \
 lua-pdns.cc lua-pdns.hh lua-recursor.cc lua-recursor.hh randomhelper.cc  \
 recpacketcache.cc recpacketcache.hh dns.cc nsecrecords.cc base32.cc cachecleaner.hh json_ws.cc json_ws.hh \
-json.cc json.hh version.hh version.cc
+json.cc json.hh version.hh version.cc responsestats.cc
 
 pdns_recursor_LDFLAGS= $(LUA_LIBS)
 pdns_recursor_LDADD= $(POLARSSL_LIBS)
index 10a7d977a4ee0e5c5011a013a589cb3974c71f8e..45df2f61651a1ade67013549977d15ef0172feb1 100644 (file)
@@ -64,6 +64,7 @@
 #include "config.h"
 #include "lua-recursor.hh"
 #include "version.hh"
+#include "responsestats.hh"
 
 #ifndef RECURSOR
 #include "statbag.hh"
@@ -488,6 +489,8 @@ void updateRcodeStats(int res)
   }
 }
 
+ResponseStats g_rs;
+
 void startDoResolve(void *p)
 {
   DNSComboWriter* dc=(DNSComboWriter *)p;
@@ -564,6 +567,7 @@ void startDoResolve(void *p)
     }
     
     if(res == RecursorBehaviour::DROP) {
+      g_rs.submitResponse(dc->d_mdp.d_qtype, 0, !dc->d_tcp);
       delete dc;
       dc=0;
       return;
@@ -580,7 +584,7 @@ void startDoResolve(void *p)
         }
       }
     }
-
+    
     if(res == RecursorBehaviour::PASS) {
       pw.getHeader()->rcode=RCode::ServFail;
       // no commit here, because no record
@@ -592,7 +596,6 @@ void startDoResolve(void *p)
       
       if(ret.size()) {
         orderAndShuffle(ret);
-        
         for(vector<DNSResourceRecord>::const_iterator i=ret.begin(); i!=ret.end(); ++i) {
           pw.startRecord(i->qname, i->qtype.getCode(), i->ttl, i->qclass, (DNSPacketWriter::Place)i->d_place); 
           minTTL = min(minTTL, i->ttl);
@@ -619,14 +622,16 @@ void startDoResolve(void *p)
       }
     }
   sendit:;
+    g_rs.submitResponse(dc->d_mdp.d_qtype, packet.size(), !dc->d_tcp);
     if(!dc->d_tcp) {
       sendto(dc->d_socket, (const char*)&*packet.begin(), packet.size(), 0, (struct sockaddr *)(&dc->d_remote), dc->d_remote.getSocklen());
       if(!SyncRes::s_nopacketcache && !variableAnswer ) {
-        t_packetCache->insertResponsePacket(string((const char*)&*packet.begin(), packet.size()), g_now.tv_sec, 
-                                           min(minTTL, 
-                                               (pw.getHeader()->rcode == RCode::ServFail) ? SyncRes::s_packetcacheservfailttl : SyncRes::s_packetcachettl
-                                               ) 
-                                          );
+        t_packetCache->insertResponsePacket(string((const char*)&*packet.begin(), packet.size()),
+                                            g_now.tv_sec, 
+                                            min(minTTL, 
+                                                (pw.getHeader()->rcode == RCode::ServFail) ? SyncRes::s_packetcacheservfailttl : SyncRes::s_packetcachettl
+                                            ) 
+        );
       }
     }
     else {
index 2afdee5c5960b51f401de40cb58bf8902d329a4c..db079be076c96683ede2dcac3e022bf3d66c7acb 100644 (file)
@@ -20,6 +20,7 @@
 #include "arguments.hh"
 #include <sys/resource.h>
 #include <sys/time.h>
+#include "responsestats.hh"
 
 #include "namespaces.hh"
 
@@ -422,6 +423,20 @@ uint64_t doGetMallocated()
   return 0;
 }
 
+extern ResponseStats g_rs;
+
+string qtypeList()
+{
+  typedef map<uint16_t, uint64_t> qtypenums_t;
+  qtypenums_t qtypenums = g_rs.getQTypeResponseCounts();
+  ostringstream os;
+  boost::format fmt("%s\t%d\n");
+  BOOST_FOREACH(const qtypenums_t::value_type& val, qtypenums) {
+    os << (fmt %DNSRecordContent::NumberToType( val.first) % val.second).str();
+  }
+  return os.str();
+}
+
 RecursorControlParser::RecursorControlParser()
 {
   addGetStat("questions", &g_stats.qcounter);
@@ -677,5 +692,9 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP
     return reloadAuthAndForwards();
   }
   
+  if(cmd=="get-qtypelist") {
+    return qtypeList();
+  }
+  
   return "Unknown command '"+cmd+"', try 'help'\n";
 }
index 9e47b9db62d4e36c09932bb18b1d247737cacc77..6e018d0227a4f089b6a8abe6e997a29812e4d791 100644 (file)
@@ -1,6 +1,7 @@
 #include "responsestats.hh"
 #include <limits>
 #include "namespaces.hh"
+#include "logger.hh"
 
 ResponseStats::ResponseStats()
 {