From 7fc95193984ff5bc1a58d9af9dcc18f7fee1d3fa Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 2 Oct 2019 10:38:53 +0200 Subject: [PATCH] dnsdist: Add per-frontend and per-server response counters --- pdns/dnsdist-carbon.cc | 2 ++ pdns/dnsdist-tcp.cc | 9 ++++++++- pdns/dnsdist-web.cc | 8 ++++++++ pdns/dnsdist.cc | 3 +++ pdns/dnsdist.hh | 2 ++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index f48c9ce61..41fc44f64 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -91,6 +91,7 @@ try boost::replace_all(serverName, ".", "_"); const string base = namespace_name + "." + hostname + "." + instance_name + ".servers." + serverName + "."; str<queries.load() << " " << now << "\r\n"; + str<responses.load() << " " << now << "\r\n"; str<reuseds.load() << " " << now << "\r\n"; str<availability != DownstreamState::Availability::Down ? state->latencyUsec/1000.0 : 0) << " " << now << "\r\n"; str<sendErrors.load() << " " << now << "\r\n"; @@ -120,6 +121,7 @@ try const string base = namespace_name + "." + hostname + "." + instance_name + ".frontends." + frontName + "."; str<queries.load() << " " << now << "\r\n"; + str<responses.load() << " " << now << "\r\n"; str<tcpDiedReadingQuery.load() << " " << now << "\r\n"; str<tcpDiedSendingResponse.load() << " " << now << "\r\n"; str<tcpGaveUp.load() << " " << now << "\r\n"; diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index c870b4d61..403fbf601 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -763,9 +763,16 @@ static void handleResponse(std::shared_ptr& state, s if (state->d_isXFR && !state->d_xfrStarted) { /* don't bother parsing the content of the response for now */ state->d_xfrStarted = true; + ++g_stats.responses; + ++state->d_ci.cs->responses; + ++state->d_ds->responses; } - ++g_stats.responses; + if (!state->d_isXFR) { + ++g_stats.responses; + ++state->d_ci.cs->responses; + ++state->d_ds->responses; + } sendResponse(state, now); } diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index eaa0a12bb..c5d4cf343 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -464,6 +464,8 @@ static void connectionThread(int sock, ComboAddress remote) output << "# HELP " << statesbase << "queries " << "Amount of queries relayed to server" << "\n"; output << "# TYPE " << statesbase << "queries " << "counter" << "\n"; + output << "# HELP " << statesbase << "responses " << "Amount of responses received from this server" << "\n"; + output << "# TYPE " << statesbase << "responses " << "counter" << "\n"; output << "# HELP " << statesbase << "drops " << "Amount of queries not answered by server" << "\n"; output << "# TYPE " << statesbase << "drops " << "counter" << "\n"; output << "# HELP " << statesbase << "latency " << "Server's latency when answering questions in milliseconds" << "\n"; @@ -507,6 +509,7 @@ static void connectionThread(int sock, ComboAddress remote) % serverName % state->remote.toStringWithPort()); output << statesbase << "queries" << label << " " << state->queries.load() << "\n"; + output << statesbase << "responses" << label << " " << state->responses.load() << "\n"; output << statesbase << "drops" << label << " " << state->reuseds.load() << "\n"; output << statesbase << "latency" << label << " " << state->latencyUsec/1000.0 << "\n"; output << statesbase << "senderrors" << label << " " << state->sendErrors.load() << "\n"; @@ -526,6 +529,8 @@ static void connectionThread(int sock, ComboAddress remote) const string frontsbase = "dnsdist_frontend_"; output << "# HELP " << frontsbase << "queries " << "Amount of queries received by this frontend" << "\n"; output << "# TYPE " << frontsbase << "queries " << "counter" << "\n"; + output << "# HELP " << frontsbase << "responses " << "Amount of responses sent by this frontend" << "\n"; + output << "# TYPE " << frontsbase << "responses " << "counter" << "\n"; output << "# HELP " << frontsbase << "tcpdiedreadingquery " << "Amount of TCP connections terminated while reading the query from the client" << "\n"; output << "# TYPE " << frontsbase << "tcpdiedreadingquery " << "counter" << "\n"; output << "# HELP " << frontsbase << "tcpdiedsendingresponse " << "Amount of TCP connections terminated while sending a response to the client" << "\n"; @@ -564,6 +569,7 @@ static void connectionThread(int sock, ComboAddress remote) % frontName % proto); output << frontsbase << "queries" << label << front->queries.load() << "\n"; + output << frontsbase << "responses" << label << front->responses.load() << "\n"; if (front->isTCP()) { output << frontsbase << "tcpdiedreadingquery" << label << front->tcpDiedReadingQuery.load() << "\n"; output << frontsbase << "tcpdiedsendingresponse" << label << front->tcpDiedSendingResponse.load() << "\n"; @@ -706,6 +712,7 @@ static void connectionThread(int sock, ComboAddress remote) {"pools", pools}, {"latency", (double)(a->latencyUsec/1000.0)}, {"queries", (double)a->queries}, + {"responses", (double)a->responses}, {"sendErrors", (double)a->sendErrors}, {"tcpDiedSendingQuery", (double)a->tcpDiedSendingQuery}, {"tcpDiedReadingResponse", (double)a->tcpDiedReadingResponse}, @@ -738,6 +745,7 @@ static void connectionThread(int sock, ComboAddress remote) { "tcp", front->tcpFD >= 0 }, { "type", front->getType() }, { "queries", (double) front->queries.load() }, + { "responses", (double) front->responses.load() }, { "tcpDiedReadingQuery", (double) front->tcpDiedReadingQuery.load() }, { "tcpDiedSendingResponse", (double) front->tcpDiedSendingResponse.load() }, { "tcpGaveUp", (double) front->tcpGaveUp.load() }, diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 901903e98..1c3f54a62 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -630,6 +630,8 @@ try { } ++g_stats.responses; + ++ids->cs->responses; + ++dss->responses; double udiff = ids->sentTime.udiff(); vinfolog("Got answer from %s, relayed to %s%s, took %f usec", dss->remote.toStringWithPort(), ids->origRemote.toStringWithPort(), @@ -1442,6 +1444,7 @@ ProcessQueryResult processQuery(DNSQuestion& dq, ClientState& cs, LocalHolders& } ++g_stats.selfAnswered; + ++cs.responses; return ProcessQueryResult::SendAnswer; } diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 9419e0eb3..e686335ad 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -679,6 +679,7 @@ struct ClientState std::shared_ptr dohFrontend{nullptr}; std::string interface; std::atomic queries{0}; + mutable std::atomic responses{0}; std::atomic tcpDiedReadingQuery{0}; std::atomic tcpDiedSendingResponse{0}; std::atomic tcpGaveUp{0}; @@ -858,6 +859,7 @@ struct DownstreamState std::atomic outstanding{0}; std::atomic reuseds{0}; std::atomic queries{0}; + std::atomic responses{0}; struct { std::atomic sendErrors{0}; std::atomic reuseds{0}; -- 2.40.0