From: bert hubert Date: Thu, 8 Aug 2013 09:47:20 +0000 (+0200) Subject: add responsestats infra, not actually reporting yet X-Git-Tag: rec-3.6.0-rc1~528^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=46c6975cb392cbf70ed366353c8160ee7f93bc3d;p=pdns add responsestats infra, not actually reporting yet --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 22204501c..254b87f34 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -60,7 +60,7 @@ randomhelper.cc namespaces.hh nsecrecords.cc base32.cc dbdnsseckeeper.cc dnsseci dnsseckeeper.hh dnssecinfra.hh base32.hh dns.cc dnssecsigner.cc polarrsakeyinfra.cc \ md5.hh signingpipe.cc signingpipe.hh dnslabeltext.cc lua-pdns.cc lua-auth.cc lua-auth.hh serialtweaker.cc \ ednssubnet.cc ednssubnet.hh cachecleaner.hh json.cc json.hh \ -version.hh version.cc rfc2136handler.cc +version.hh version.cc rfc2136handler.cc responsestats.cc responsestats.hh # pdns_server_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@ $(BOOST_SERIALIZATION_LDFLAGS) -rdynamic @@ -158,7 +158,10 @@ nsec3dig_LDADD= $(POLARSSL_LIBS) toysdig_SOURCES=toysdig.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \ misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \ logger.cc statbag.cc qtype.cc sillyrecords.cc nsecrecords.cc base32.cc \ - ednssubnet.cc ednssubnet.hh + ednssubnet.cc ednssubnet.hh aes/aescpp.h \ + aes/aescrypt.c aes/aes.h aes/aeskey.c aes/aes_modes.c aes/aesopt.h \ + aes/aestab.c aes/aestab.h aes/brg_endian.h aes/brg_types.h aes/dns_random.cc \ + randomhelper.cc #tcptorture_SOURCES=tcptorture.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \ diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index d3268114e..e7d32a27b 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -23,6 +23,7 @@ #include #include #include +#include "responsestats.hh" #include #include "dns.hh" #include "dnsbackend.hh" @@ -235,10 +236,15 @@ UDPNameserver::UDPNameserver() if(::arg()["local-address"].empty() && ::arg()["local-ipv6"].empty()) L<getString(); + g_rs.submitResponse(p->qtype.getCode(), buffer.length(), true); + struct msghdr msgh; struct cmsghdr *cmsg; struct iovec iov; @@ -313,7 +319,7 @@ void UDPNameserver::send(DNSPacket *p) } DLOG(L<getRemote() <<" ("<< buffer.length()<<" octets)"< p->getMaxReplyLen()) { - cerr<<"Weird, trying to send a message that needs truncation, "<< buffer.length()<<" > "<getMaxReplyLen()< "<getMaxReplyLen()<getSocket(), &msgh, 0) < 0) L< +#include "namespaces.hh" + +ResponseStats::ResponseStats() +{ + d_qtypecounters.resize(std::numeric_limits::max()); + d_sizecounters.push_back(make_pair(20,0)); + d_sizecounters.push_back(make_pair(40,0)); + d_sizecounters.push_back(make_pair(60,0)); + d_sizecounters.push_back(make_pair(80,0)); + d_sizecounters.push_back(make_pair(100,0)); + d_sizecounters.push_back(make_pair(150,0)); + for(int n=200; n < 65000 ; n+=200) + d_sizecounters.push_back(make_pair(n,0)); + d_sizecounters.push_back(make_pair(std::numeric_limits::max(),0)); +} + +static bool pcomp(const pair&a , const pair&b) +{ + return a.first < b.first; +} + +void ResponseStats::submitResponse(uint16_t qtype, uint16_t respsize, bool udpOrTCP) +{ + d_qtypecounters[qtype]++; + pair s(respsize, 0); + sizecounters_t::iterator iter = std::upper_bound(d_sizecounters.begin(), d_sizecounters.end(), s, pcomp); + if(iter!= d_sizecounters.begin()) + --iter; + iter->second++; +} + +map ResponseStats::getQTypeResponseCounts() +{ + map ret; + uint64_t count; + for(int i = 0 ; i < d_qtypecounters.size() ; ++i) { + count= d_qtypecounters[i]; + if(count) + ret[i]=count; + } + return ret; +} diff --git a/pdns/responsestats.hh b/pdns/responsestats.hh new file mode 100644 index 000000000..e2d768a32 --- /dev/null +++ b/pdns/responsestats.hh @@ -0,0 +1,20 @@ +#ifndef PDNS_RESPONSESTATS_HH +#define PDNS_RESPONSESTATS_HH +#include "misc.hh" + +class ResponseStats +{ +public: + ResponseStats(); + + void submitResponse(uint16_t qtype, uint16_t respsize, bool udpOrTCP); + map getQTypeResponseCounts(); + map getSizeResponseCounts(); + +private: + vector d_qtypecounters; + typedef vector > sizecounters_t; + sizecounters_t d_sizecounters; +}; + +#endif