Permalink
Browse files

Added qtype statistics to recursor and rec_control (get-qtypelist)

  • Loading branch information...
1 parent 2a4f2b8 commit 79332bff53999484f04e0372cbdf6c77eb3c8433 @Fusl Fusl committed Jan 21, 2014
Showing with 33 additions and 8 deletions.
  1. +1 −1 pdns/Makefile.am
  2. +12 −7 pdns/pdns_recursor.cc
  3. +19 −0 pdns/rec_channel_rec.cc
  4. +1 −0 pdns/responsestats.cc
View
@@ -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)
View
@@ -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 {
@@ -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";
}
@@ -1,6 +1,7 @@
#include "responsestats.hh"
#include <limits>
#include "namespaces.hh"
+#include "logger.hh"
ResponseStats::ResponseStats()
{

0 comments on commit 79332bf

Please sign in to comment.