From 963bef8d193ac6f259303c152f6a44df46229ddc Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 2 Dec 2015 16:27:40 +0100 Subject: [PATCH] Add per-frontend stats to dnsdist For now, we only display the number of queries received for each frontend, separating TCP and UDP. --- pdns/dnsdist-carbon.cc | 9 +++++++++ pdns/dnsdist-tcp.cc | 3 +++ pdns/dnsdist.cc | 9 +++++++-- pdns/dnsdist.hh | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index e88dbc71b..a5130ec15 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -67,6 +67,15 @@ try str<sendErrors.load() << " " << now << "\r\n"; str<outstanding.load() << " " << now << "\r\n"; } + for(const auto& front : g_frontends) { + if (front->udpFD == -1 && front->tcpFD == -1) + continue; + + string frontName = front->local.toStringWithPort() + (front->udpFD >= 0 ? "_udp" : "_tcp"); + boost::replace_all(frontName, ".", "_"); + const string base = "dnsdist." + hostname + ".main.frontends." + frontName + "."; + str<queries.load() << " " << now << "\r\n"; + } const string msg = str.str(); int ret = waitForRWData(s.getHandle(), false, 1 , 0); diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 7a93ba7d8..a7ecd2124 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -341,6 +341,9 @@ void* tcpAcceptorThread(void* p) ci = new ConnectionInfo; ci->fd = -1; ci->fd = SAccept(cs->tcpFD, remote); + + g_stats.queries++; + cs->queries++; if(!acl->match(remote)) { g_stats.aclDrops++; diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 5f78dceda..0e3f2f3d2 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -64,6 +64,7 @@ bool g_console; GlobalStateHolder g_ACL; string g_outputBuffer; vector> g_locals; +vector g_frontends; /* UDP: the grand design. Per socket we listen on for incoming queries there is one thread. Then we have a bunch of connected sockets for talking to downstream servers. @@ -441,6 +442,9 @@ try try { len = recvmsg(cs->udpFD, &msgh, 0); + cs->queries++; + g_stats.queries++; + if(len < (int)sizeof(struct dnsheader)) { g_stats.nonCompliantQueries++; continue; @@ -453,7 +457,6 @@ try continue; } - g_stats.queries++; if(!acl->match(remote)) { vinfolog("Query from %s dropped because of ACL", remote.toStringWithPort()); g_stats.aclDrops++; @@ -1272,14 +1275,15 @@ try SBind(cs->udpFD, cs->local); toLaunch.push_back(cs); + g_frontends.push_back(cs); } for(const auto& local : g_locals) { - ClientState* cs = new ClientState; if(!local.second) { // no TCP/IP warnlog("Not providing TCP/IP service on local address '%s'", local.first.toStringWithPort()); continue; } + ClientState* cs = new ClientState; cs->local= local.first; cs->tcpFD = SSocket(cs->local.sin4.sin_family, SOCK_STREAM, 0); @@ -1298,6 +1302,7 @@ try warnlog("Listening on %s",cs->local.toStringWithPort()); toLaunch.push_back(cs); + g_frontends.push_back(cs); } uid_t newgid=0; diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index a778dd58d..6a78c35b4 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -217,6 +217,7 @@ extern Rings g_rings; struct ClientState { ComboAddress local; + std::atomic queries{0}; int udpFD{-1}; int tcpFD{-1}; }; @@ -355,6 +356,7 @@ extern GlobalStateHolder g_ACL; extern ComboAddress g_serverControl; // not changed during runtime extern std::vector> g_locals; // not changed at runtime (we hope XXX) +extern vector g_frontends; extern std::string g_key; // in theory needs locking extern bool g_truncateTC; extern int g_tcpRecvTimeout; -- 2.40.0