From: Fusl Date: Tue, 21 Jan 2014 13:15:34 +0000 (+0100) Subject: Added qtype statistics to recursor and rec_control (get-qtypelist) X-Git-Tag: rec-3.6.0-rc1~231^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=79332bff53999484f04e0372cbdf6c77eb3c8433;p=thirdparty%2Fpdns.git Added qtype statistics to recursor and rec_control (get-qtypelist) --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index cb8541f903..70372fd8f4 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -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) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 10a7d977a4..45df2f6165 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -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::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 { diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 2afdee5c59..db079be076 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -20,6 +20,7 @@ #include "arguments.hh" #include #include +#include "responsestats.hh" #include "namespaces.hh" @@ -422,6 +423,20 @@ uint64_t doGetMallocated() return 0; } +extern ResponseStats g_rs; + +string qtypeList() +{ + typedef map 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"; } diff --git a/pdns/responsestats.cc b/pdns/responsestats.cc index 9e47b9db62..6e018d0227 100644 --- a/pdns/responsestats.cc +++ b/pdns/responsestats.cc @@ -1,6 +1,7 @@ #include "responsestats.hh" #include #include "namespaces.hh" +#include "logger.hh" ResponseStats::ResponseStats() {