From: Pieter Lexis Date: Wed, 15 Jul 2015 10:21:36 +0000 (+0200) Subject: Centralize response statistics gathering X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~58^2~5^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b552d7b109bf52f6314b1dd218c3f6b6f0a22551;p=thirdparty%2Fpdns.git Centralize response statistics gathering * Add `tcp-answers-bytes` counter * Update documentation * Add newly needed files to recursor distribution Closes #2576 Closes #1412 (or was already fixed) --- diff --git a/build-scripts/dist-recursor b/build-scripts/dist-recursor index dc61002667..c5b5aae7da 100755 --- a/build-scripts/dist-recursor +++ b/build-scripts/dist-recursor @@ -35,7 +35,7 @@ mplexer.hh pubsuffix.hh \ dns_random.hh lua-pdns.hh lua-recursor.hh namespaces.hh \ recpacketcache.hh base32.hh cachecleaner.hh json.hh version.hh \ ws-recursor.hh ws-api.hh secpoll-recursor.hh \ -responsestats.hh webserver.hh dnsname.hh" +responsestats.hh webserver.hh dnsname.hh dnspacket.hh ednssubnet.hh" CFILES="syncres.cc iputils.cc misc.cc unix_utility.cc qtype.cc \ logger.cc arguments.cc lwres.cc pdns_recursor.cc lua-iputils.cc \ diff --git a/docs/markdown/authoritative/performance.md b/docs/markdown/authoritative/performance.md index 557dff9b6a..804db53d17 100644 --- a/docs/markdown/authoritative/performance.md +++ b/docs/markdown/authoritative/performance.md @@ -73,11 +73,16 @@ daemon. * `signatures`: Number of DNSSEC signatures created * `sys-msec`: Number of CPU miliseconds sent in system time * `tcp-answers`: Number of answers sent out over TCP -* `tcp-questions`: Number of questions received over TCP +* `tcp-answers-bytes`: Total number of answer bytes sent over TCP (since 4.0.0) +* `tcp-queries`: Number of questions received over TCP +* `tcp4-answers`: Number of answers sent out over TCPv4 +* `tcp4-queries`: Number of questions received over TCPv4 +* `tcp6-answers`: Number of answers sent out over TCPv6 +* `tcp6-queries`: Number of questions received over TCPv6 * `timedout-questions`: Amount of packets that were dropped because they had to wait too long internally * `udp-answers`: Number of answers sent out over UDP -* `udp-queries`: Number of questions received over UDP * `udp-answers-bytes`: Total number of answer bytes sent over UDP +* `udp-queries`: Number of questions received over UDP * `udp-do-queries`: Number of queries received with the DO (DNSSEC OK) bit set * `udp-in-errors`: Number of packets, received faster than the OS could process them * `udp-noport-errors`: Number of UDP packets where an ICMP response was received that the remote port was not listening diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 49acfc0141..8bdf2a9049 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -177,7 +177,7 @@ pdns_server_SOURCES = \ rcpgenerator.cc \ receiver.cc \ resolver.cc resolver.hh \ - responsestats.cc responsestats.hh \ + responsestats.cc responsestats.hh responsestats-auth.cc \ rfc2136handler.cc \ secpoll-auth.cc secpoll-auth.hh \ serialtweaker.cc \ diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 1894bcf36e..fb0ade2fb0 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -241,6 +241,7 @@ void declareStats(void) S.declare("signatures", "Number of DNSSEC signatures made"); S.declare("tcp-queries","Number of TCP queries received"); S.declare("tcp-answers","Number of answers sent out over TCP"); + S.declare("tcp-answers-bytes","Total size of answers sent out over TCP"); S.declare("tcp4-queries","Number of IPv4 TCP queries received"); S.declare("tcp4-answers","Number of IPv4 answers sent out over TCP"); diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index 6a6819392f..c5539af22c 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -275,39 +275,15 @@ UDPNameserver::UDPNameserver( bool additional_socket ) L<getString(); - static AtomicCounter &numanswered=*S.getPointer("udp-answers"); - static AtomicCounter &numanswered4=*S.getPointer("udp4-answers"); - static AtomicCounter &numanswered6=*S.getPointer("udp6-answers"); - static AtomicCounter &bytesanswered=*S.getPointer("udp-answers-bytes"); - - g_rs.submitResponse(p->qtype.getCode(), buffer.length(), true); + string buffer=p->getString(); + g_rs.submitResponse(*p, true); struct msghdr msgh; struct iovec iov; char cbuf[256]; - /* Query statistics */ - if(p->d.aa) { - if (p->d.rcode==RCode::NXDomain) - S.ringAccount("nxdomain-queries",p->qdomain.toString()+"/"+p->qtype.getName()); - } else if (p->isEmpty()) { - S.ringAccount("unauth-queries",p->qdomain.toString()+"/"+p->qtype.getName()); - S.ringAccount("remotes-unauth",p->d_remote); - } - - /* Count responses (total/v4/v6) and byte counts */ - numanswered++; - bytesanswered+=buffer.length(); - if(p->d_remote.sin4.sin_family==AF_INET) - numanswered4++; - else - numanswered6++; - fillMSGHdr(&msgh, &iov, cbuf, 0, (char*)buffer.c_str(), buffer.length(), &p->d_remote); if(p->d_anyLocal) { diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index fabc2f88c1..232736a3ee 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -520,8 +520,6 @@ void updateResponseStats(int res, const ComboAddress& remote, unsigned int packe } } -ResponseStats g_rs; - static string makeLoginfo(DNSComboWriter* dc) try { diff --git a/pdns/responsestats-auth.cc b/pdns/responsestats-auth.cc new file mode 100644 index 0000000000..f4180a9635 --- /dev/null +++ b/pdns/responsestats-auth.cc @@ -0,0 +1,46 @@ +#include "responsestats.hh" +#include "dnspacket.hh" +#include "statbag.hh" + +extern StatBag S; +/** + * Function that creates all the stats + * when udpOrTCP is true, it is udp + */ +void ResponseStats::submitResponse(DNSPacket &p, bool udpOrTCP) { + const string& buf=p.getString(); + static AtomicCounter &udpnumanswered=*S.getPointer("udp-answers"); + static AtomicCounter &udpnumanswered4=*S.getPointer("udp4-answers"); + static AtomicCounter &udpnumanswered6=*S.getPointer("udp6-answers"); + static AtomicCounter &udpbytesanswered=*S.getPointer("udp-answers-bytes"); + static AtomicCounter &tcpnumanswered=*S.getPointer("tcp-answers"); + static AtomicCounter &tcpnumanswered4=*S.getPointer("tcp4-answers"); + static AtomicCounter &tcpnumanswered6=*S.getPointer("tcp6-answers"); + static AtomicCounter &tcpbytesanswered=*S.getPointer("tcp-answers-bytes"); + + if(p.d.aa) { + if (p.d.rcode==RCode::NXDomain) + S.ringAccount("nxdomain-queries",p.qdomain.toString()+"/"+p.qtype.getName()); + } else if (p.isEmpty()) { + S.ringAccount("unauth-queries",p.qdomain.toString()+"/"+p.qtype.getName()); + S.ringAccount("remotes-unauth",p.d_remote); + } + + if (udpOrTCP) { // udp + udpnumanswered++; + udpbytesanswered+=buf.length(); + if(p.d_remote.sin4.sin_family==AF_INET) + udpnumanswered4++; + else + udpnumanswered6++; + } else { //tcp + tcpnumanswered++; + tcpbytesanswered+=buf.length(); + if(p.d_remote.sin4.sin_family==AF_INET) + tcpnumanswered4++; + else + tcpnumanswered6++; + } + + submitResponse(p.qtype.getCode(), buf.length(), udpOrTCP); +} diff --git a/pdns/responsestats.cc b/pdns/responsestats.cc index ff4168da39..45eaad0d82 100644 --- a/pdns/responsestats.cc +++ b/pdns/responsestats.cc @@ -22,6 +22,8 @@ ResponseStats::ResponseStats() d_sizecounters.push_back(make_pair(std::numeric_limits::max(),0)); } +ResponseStats g_rs = ResponseStats(); + static bool pcomp(const pair&a , const pair&b) { return a.first < b.first; diff --git a/pdns/responsestats.hh b/pdns/responsestats.hh index 45fe23225a..dfb04a86ca 100644 --- a/pdns/responsestats.hh +++ b/pdns/responsestats.hh @@ -1,12 +1,13 @@ -#ifndef PDNS_RESPONSESTATS_HH -#define PDNS_RESPONSESTATS_HH +#pragma once #include "misc.hh" +#include "dnspacket.hh" class ResponseStats { public: ResponseStats(); + void submitResponse(DNSPacket &p, bool udpOrTCP); void submitResponse(uint16_t qtype, uint16_t respsize, bool udpOrTCP); map getQTypeResponseCounts(); map getSizeResponseCounts(); @@ -18,4 +19,4 @@ private: sizecounters_t d_sizecounters; }; -#endif +extern ResponseStats g_rs; diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index 5d25068b09..bb141f830a 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -179,17 +179,7 @@ void connectWithTimeout(int fd, struct sockaddr* remote, size_t socklen) void TCPNameserver::sendPacket(shared_ptr p, int outsock) { - - /* Query statistics */ - if(p->qtype.getCode()!=QType::AXFR && p->qtype.getCode()!=QType::IXFR) { - if(p->d.aa) { - if(p->d.rcode==RCode::NXDomain) - S.ringAccount("nxdomain-queries",p->qdomain.toString()+"/"+p->qtype.getName()); - } else if(p->isEmpty()) { - S.ringAccount("unauth-queries",p->qdomain.toString()+"/"+p->qtype.getName()); - S.ringAccount("remotes-unauth",p->d_remote); - } - } + g_rs.submitResponse(*p, false); uint16_t len=htons(p->getString().length()); string buffer((const char*)&len, 2); @@ -347,8 +337,6 @@ void *TCPNameserver::doConnection(void *data) if(LPE) LPE->police(&(*packet), &(*cached), true); sendPacket(cached, fd); // presigned, don't do it again - incTCPAnswerCount(remote); - continue; } if(logDNSQueries) @@ -373,8 +361,7 @@ void *TCPNameserver::doConnection(void *data) if(!reply) // unable to write an answer? break; - - incTCPAnswerCount(remote); + sendPacket(reply, fd); } }