From: Remi Gacogne Date: Mon, 22 Mar 2021 16:12:46 +0000 (+0100) Subject: dnsdist: Add 'max concurrent connections' counters X-Git-Tag: rec-4.6.0-alpha0~1^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cc8416ef816b86b31cb1a26a080d3634d51a7943;p=thirdparty%2Fpdns.git dnsdist: Add 'max concurrent connections' counters --- diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index db0dd411df..9d973b454b 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -104,6 +104,7 @@ void carbonDumpThread() str<tcpWriteTimeouts.load() << " " << now << "\r\n"; str<tcpConnectTimeouts.load() << " " << now << "\r\n"; str<tcpCurrentConnections.load() << " " << now << "\r\n"; + str<tcpMaxConcurrentConnections.load() << " " << now << "\r\n"; str<tcpNewConnections.load() << " " << now << "\r\n"; str<tcpReusedConnections.load() << " " << now << "\r\n"; str<tcpAvgQueriesPerConnection.load() << " " << now << "\r\n"; @@ -132,6 +133,7 @@ void carbonDumpThread() str<tcpClientTimeouts.load() << " " << now << "\r\n"; str<tcpDownstreamTimeouts.load() << " " << now << "\r\n"; str<tcpCurrentConnections.load() << " " << now << "\r\n"; + str<tcpMaxConcurrentConnections.load() << " " << now << "\r\n"; str<tcpAvgQueriesPerConnection.load() << " " << now << "\r\n"; str<tcpAvgConnectionDuration.load() << " " << now << "\r\n"; str<tls10queries.load() << " " << now << "\r\n"; diff --git a/pdns/dnsdist-lua-inspection.cc b/pdns/dnsdist-lua-inspection.cc index a21d38a47e..f23430d643 100644 --- a/pdns/dnsdist-lua-inspection.cc +++ b/pdns/dnsdist-lua-inspection.cc @@ -601,24 +601,24 @@ void setupLuaInspection(LuaContext& luaCtx) ret << endl; ret << "Frontends:" << endl; - fmt = boost::format("%-3d %-20.20s %-20d %-20d %-25d %-20d %-20d %-20d %-20f %-20f %-20d %-20d %-25d %-25d %-15d %-15d %-15d %-15d %-15d"); - ret << (fmt % "#" % "Address" % "Connections" % "Died reading query" % "Died sending response" % "Gave up" % "Client timeouts" % "Downstream timeouts" % "Avg queries/conn" % "Avg duration" % "TLS new sessions" % "TLS Resumptions" % "TLS unknown ticket keys" % "TLS inactive ticket keys" % "TLS 1.0" % "TLS 1.1" % "TLS 1.2" % "TLS 1.3" % "TLS other") << endl; + fmt = boost::format("%-3d %-20.20s %-20d %-20d %-20d %-25d %-20d %-20d %-20d %-20f %-20f %-20d %-20d %-25d %-25d %-15d %-15d %-15d %-15d %-15d"); + ret << (fmt % "#" % "Address" % "Connections" % "Max concurrent conn" % "Died reading query" % "Died sending response" % "Gave up" % "Client timeouts" % "Downstream timeouts" % "Avg queries/conn" % "Avg duration" % "TLS new sessions" % "TLS Resumptions" % "TLS unknown ticket keys" % "TLS inactive ticket keys" % "TLS 1.0" % "TLS 1.1" % "TLS 1.2" % "TLS 1.3" % "TLS other") << endl; size_t counter = 0; for(const auto& f : g_frontends) { - ret << (fmt % counter % f->local.toStringWithPort() % f->tcpCurrentConnections % f->tcpDiedReadingQuery % f->tcpDiedSendingResponse % f->tcpGaveUp % f->tcpClientTimeouts % f->tcpDownstreamTimeouts % f->tcpAvgQueriesPerConnection % f->tcpAvgConnectionDuration % f->tlsNewSessions % f->tlsResumptions % f->tlsUnknownTicketKey % f->tlsInactiveTicketKey % f->tls10queries % f->tls11queries % f->tls12queries % f->tls13queries % f->tlsUnknownqueries) << endl; + ret << (fmt % counter % f->local.toStringWithPort() % f->tcpCurrentConnections % f->tcpMaxConcurrentConnections % f->tcpDiedReadingQuery % f->tcpDiedSendingResponse % f->tcpGaveUp % f->tcpClientTimeouts % f->tcpDownstreamTimeouts % f->tcpAvgQueriesPerConnection % f->tcpAvgConnectionDuration % f->tlsNewSessions % f->tlsResumptions % f->tlsUnknownTicketKey % f->tlsInactiveTicketKey % f->tls10queries % f->tls11queries % f->tls12queries % f->tls13queries % f->tlsUnknownqueries) << endl; ++counter; } ret << endl; ret << "Backends:" << endl; - fmt = boost::format("%-3d %-20.20s %-20.20s %-20d %-20d %-25d %-20d %-20d %-20d %-20d %-20d %20d %-20f %-20f"); - ret << (fmt % "#" % "Name" % "Address" % "Connections" % "Died sending query" % "Died reading response" % "Gave up" % "Read timeouts" % "Write timeouts" % "Connect timeouts" % "Total connections" % "Reused connections" % "Avg queries/conn" % "Avg duration") << endl; + fmt = boost::format("%-3d %-20.20s %-20.20s %-20d %-20d %-25d %-20d %-20d %-20d %-20d %-20d %-20d %-20d %-20f %-20f"); + ret << (fmt % "#" % "Name" % "Address" % "Connections" % " Max concurrent conn" % "Died sending query" % "Died reading response" % "Gave up" % "Read timeouts" % "Write timeouts" % "Connect timeouts" % "Total connections" % "Reused connections" % "Avg queries/conn" % "Avg duration") << endl; auto states = g_dstates.getLocal(); counter = 0; for(const auto& s : *states) { - ret << (fmt % counter % s->getName() % s->remote.toStringWithPort() % s->tcpCurrentConnections % s->tcpDiedSendingQuery % s->tcpDiedReadingResponse % s->tcpGaveUp % s->tcpReadTimeouts % s->tcpWriteTimeouts % s->tcpConnectTimeouts % s->tcpNewConnections % s->tcpReusedConnections % s->tcpAvgQueriesPerConnection % s->tcpAvgConnectionDuration) << endl; + ret << (fmt % counter % s->getName() % s->remote.toStringWithPort() % s->tcpCurrentConnections % s->tcpMaxConcurrentConnections % s->tcpDiedSendingQuery % s->tcpDiedReadingResponse % s->tcpGaveUp % s->tcpReadTimeouts % s->tcpWriteTimeouts % s->tcpConnectTimeouts % s->tcpNewConnections % s->tcpReusedConnections % s->tcpAvgQueriesPerConnection % s->tcpAvgConnectionDuration) << endl; ++counter; } diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index cb11142a79..19185d9d53 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -1231,7 +1231,10 @@ void tcpAcceptorThread(ClientState* cs) ci->fd = accept(cs->tcpFD, reinterpret_cast(&remote), &remlen); #endif // will be decremented when the ConnectionInfo object is destroyed, no matter the reason - ++cs->tcpCurrentConnections; + auto concurrentConnections = ++cs->tcpCurrentConnections; + if (concurrentConnections > cs->tcpMaxConcurrentConnections) { + cs->tcpMaxConcurrentConnections = concurrentConnections; + } if (ci->fd < 0) { throw std::runtime_error((boost::format("accepting new connection on socket: %s") % stringerror()).str()); diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index 05f280dfec..9d31b3aefa 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -447,46 +447,48 @@ static void handlePrometheus(const YaHTTP::Request& req, YaHTTP::Response& resp) auto states = g_dstates.getLocal(); const string statesbase = "dnsdist_server_"; - output << "# HELP " << statesbase << "status " << "Whether this backend is up (1) or down (0)" << "\n"; - output << "# TYPE " << statesbase << "status " << "gauge" << "\n"; - 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"; - output << "# TYPE " << statesbase << "latency " << "gauge" << "\n"; - output << "# HELP " << statesbase << "senderrors " << "Total number of OS send errors while relaying queries" << "\n"; - output << "# TYPE " << statesbase << "senderrors " << "counter" << "\n"; - output << "# HELP " << statesbase << "outstanding " << "Current number of queries that are waiting for a backend response" << "\n"; - output << "# TYPE " << statesbase << "outstanding " << "gauge" << "\n"; - output << "# HELP " << statesbase << "order " << "The order in which this server is picked" << "\n"; - output << "# TYPE " << statesbase << "order " << "gauge" << "\n"; - output << "# HELP " << statesbase << "weight " << "The weight within the order in which this server is picked" << "\n"; - output << "# TYPE " << statesbase << "weight " << "gauge" << "\n"; - output << "# HELP " << statesbase << "tcpdiedsendingquery " << "The number of TCP I/O errors while sending the query" << "\n"; - output << "# TYPE " << statesbase << "tcpdiedsendingquery " << "counter" << "\n"; - output << "# HELP " << statesbase << "tcpdiedreadingresponse " << "The number of TCP I/O errors while reading the response" << "\n"; - output << "# TYPE " << statesbase << "tcpdiedreadingresponse " << "counter" << "\n"; - output << "# HELP " << statesbase << "tcpgaveup " << "The number of TCP connections failing after too many attempts" << "\n"; - output << "# TYPE " << statesbase << "tcpgaveup " << "counter" << "\n"; - output << "# HELP " << statesbase << "tcpconnecttimeouts " << "The number of TCP connect timeouts" << "\n"; - output << "# TYPE " << statesbase << "tcpconnecttimeouts " << "counter" << "\n"; - output << "# HELP " << statesbase << "tcpreadtimeouts " << "The number of TCP read timeouts" << "\n"; - output << "# TYPE " << statesbase << "tcpreadtimeouts " << "counter" << "\n"; - output << "# HELP " << statesbase << "tcpwritetimeouts " << "The number of TCP write timeouts" << "\n"; - output << "# TYPE " << statesbase << "tcpwritetimeouts " << "counter" << "\n"; - output << "# HELP " << statesbase << "tcpcurrentconnections " << "The number of current TCP connections" << "\n"; - output << "# TYPE " << statesbase << "tcpcurrentconnections " << "gauge" << "\n"; - output << "# HELP " << statesbase << "tcpnewconnections " << "The number of established TCP connections in total" << "\n"; - output << "# TYPE " << statesbase << "tcpnewconnections " << "counter" << "\n"; - output << "# HELP " << statesbase << "tcpreusedconnections " << "The number of times a TCP connection has been reused" << "\n"; - output << "# TYPE " << statesbase << "tcpreusedconnections " << "counter" << "\n"; - output << "# HELP " << statesbase << "tcpavgqueriesperconn " << "The average number of queries per TCP connection" << "\n"; - output << "# TYPE " << statesbase << "tcpavgqueriesperconn " << "gauge" << "\n"; - output << "# HELP " << statesbase << "tcpavgconnduration " << "The average duration of a TCP connection (ms)" << "\n"; - output << "# TYPE " << statesbase << "tcpavgconnduration " << "gauge" << "\n"; + output << "# HELP " << statesbase << "status " << "Whether this backend is up (1) or down (0)" << "\n"; + output << "# TYPE " << statesbase << "status " << "gauge" << "\n"; + 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"; + output << "# TYPE " << statesbase << "latency " << "gauge" << "\n"; + output << "# HELP " << statesbase << "senderrors " << "Total number of OS send errors while relaying queries" << "\n"; + output << "# TYPE " << statesbase << "senderrors " << "counter" << "\n"; + output << "# HELP " << statesbase << "outstanding " << "Current number of queries that are waiting for a backend response" << "\n"; + output << "# TYPE " << statesbase << "outstanding " << "gauge" << "\n"; + output << "# HELP " << statesbase << "order " << "The order in which this server is picked" << "\n"; + output << "# TYPE " << statesbase << "order " << "gauge" << "\n"; + output << "# HELP " << statesbase << "weight " << "The weight within the order in which this server is picked" << "\n"; + output << "# TYPE " << statesbase << "weight " << "gauge" << "\n"; + output << "# HELP " << statesbase << "tcpdiedsendingquery " << "The number of TCP I/O errors while sending the query" << "\n"; + output << "# TYPE " << statesbase << "tcpdiedsendingquery " << "counter" << "\n"; + output << "# HELP " << statesbase << "tcpdiedreadingresponse " << "The number of TCP I/O errors while reading the response" << "\n"; + output << "# TYPE " << statesbase << "tcpdiedreadingresponse " << "counter" << "\n"; + output << "# HELP " << statesbase << "tcpgaveup " << "The number of TCP connections failing after too many attempts" << "\n"; + output << "# TYPE " << statesbase << "tcpgaveup " << "counter" << "\n"; + output << "# HELP " << statesbase << "tcpconnecttimeouts " << "The number of TCP connect timeouts" << "\n"; + output << "# TYPE " << statesbase << "tcpconnecttimeouts " << "counter" << "\n"; + output << "# HELP " << statesbase << "tcpreadtimeouts " << "The number of TCP read timeouts" << "\n"; + output << "# TYPE " << statesbase << "tcpreadtimeouts " << "counter" << "\n"; + output << "# HELP " << statesbase << "tcpwritetimeouts " << "The number of TCP write timeouts" << "\n"; + output << "# TYPE " << statesbase << "tcpwritetimeouts " << "counter" << "\n"; + output << "# HELP " << statesbase << "tcpcurrentconnections " << "The number of current TCP connections" << "\n"; + output << "# TYPE " << statesbase << "tcpcurrentconnections " << "gauge" << "\n"; + output << "# HELP " << statesbase << "tcpmaxconcurrentconnections " << "The maximum number of concurrent TCP connections" << "\n"; + output << "# TYPE " << statesbase << "tcpmaxconcurrentconnections " << "counter" << "\n"; + output << "# HELP " << statesbase << "tcpnewconnections " << "The number of established TCP connections in total" << "\n"; + output << "# TYPE " << statesbase << "tcpnewconnections " << "counter" << "\n"; + output << "# HELP " << statesbase << "tcpreusedconnections " << "The number of times a TCP connection has been reused" << "\n"; + output << "# TYPE " << statesbase << "tcpreusedconnections " << "counter" << "\n"; + output << "# HELP " << statesbase << "tcpavgqueriesperconn " << "The average number of queries per TCP connection" << "\n"; + output << "# TYPE " << statesbase << "tcpavgqueriesperconn " << "gauge" << "\n"; + output << "# HELP " << statesbase << "tcpavgconnduration " << "The average duration of a TCP connection (ms)" << "\n"; + output << "# TYPE " << statesbase << "tcpavgconnduration " << "gauge" << "\n"; for (const auto& state : *states) { string serverName; @@ -501,26 +503,27 @@ static void handlePrometheus(const YaHTTP::Request& req, YaHTTP::Response& resp) const std::string label = boost::str(boost::format("{server=\"%1%\",address=\"%2%\"}") % serverName % state->remote.toStringWithPort()); - output << statesbase << "status" << label << " " << (state->isUp() ? "1" : "0") << "\n"; - 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"; - output << statesbase << "outstanding" << label << " " << state->outstanding.load() << "\n"; - output << statesbase << "order" << label << " " << state->order << "\n"; - output << statesbase << "weight" << label << " " << state->weight << "\n"; - output << statesbase << "tcpdiedsendingquery" << label << " " << state->tcpDiedSendingQuery << "\n"; - output << statesbase << "tcpdiedreadingresponse" << label << " " << state->tcpDiedReadingResponse << "\n"; - output << statesbase << "tcpgaveup" << label << " " << state->tcpGaveUp << "\n"; - output << statesbase << "tcpreadtimeouts" << label << " " << state->tcpReadTimeouts << "\n"; - output << statesbase << "tcpwritetimeouts" << label << " " << state->tcpWriteTimeouts << "\n"; - output << statesbase << "tcpconnecttimeouts" << label << " " << state->tcpConnectTimeouts << "\n"; - output << statesbase << "tcpcurrentconnections" << label << " " << state->tcpCurrentConnections << "\n"; - output << statesbase << "tcpnewconnections" << label << " " << state->tcpNewConnections << "\n"; - output << statesbase << "tcpreusedconnections" << label << " " << state->tcpReusedConnections << "\n"; - output << statesbase << "tcpavgqueriesperconn" << label << " " << state->tcpAvgQueriesPerConnection << "\n"; - output << statesbase << "tcpavgconnduration" << label << " " << state->tcpAvgConnectionDuration << "\n"; + output << statesbase << "status" << label << " " << (state->isUp() ? "1" : "0") << "\n"; + 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"; + output << statesbase << "outstanding" << label << " " << state->outstanding.load() << "\n"; + output << statesbase << "order" << label << " " << state->order << "\n"; + output << statesbase << "weight" << label << " " << state->weight << "\n"; + output << statesbase << "tcpdiedsendingquery" << label << " " << state->tcpDiedSendingQuery << "\n"; + output << statesbase << "tcpdiedreadingresponse" << label << " " << state->tcpDiedReadingResponse << "\n"; + output << statesbase << "tcpgaveup" << label << " " << state->tcpGaveUp << "\n"; + output << statesbase << "tcpreadtimeouts" << label << " " << state->tcpReadTimeouts << "\n"; + output << statesbase << "tcpwritetimeouts" << label << " " << state->tcpWriteTimeouts << "\n"; + output << statesbase << "tcpconnecttimeouts" << label << " " << state->tcpConnectTimeouts << "\n"; + output << statesbase << "tcpcurrentconnections" << label << " " << state->tcpCurrentConnections << "\n"; + output << statesbase << "tcpmaxconcurrentconnections" << label << " " << state->tcpMaxConcurrentConnections << "\n"; + output << statesbase << "tcpnewconnections" << label << " " << state->tcpNewConnections << "\n"; + output << statesbase << "tcpreusedconnections" << label << " " << state->tcpReusedConnections << "\n"; + output << statesbase << "tcpavgqueriesperconn" << label << " " << state->tcpAvgQueriesPerConnection << "\n"; + output << statesbase << "tcpavgconnduration" << label << " " << state->tcpAvgConnectionDuration << "\n"; } const string frontsbase = "dnsdist_frontend_"; @@ -540,6 +543,8 @@ static void handlePrometheus(const YaHTTP::Request& req, YaHTTP::Response& resp) output << "# TYPE " << frontsbase << "tcpdownstreamtimeouts " << "counter" << "\n"; output << "# HELP " << frontsbase << "tcpcurrentconnections " << "Amount of current incoming TCP connections from clients" << "\n"; output << "# TYPE " << frontsbase << "tcpcurrentconnections " << "gauge" << "\n"; + output << "# HELP " << frontsbase << "tcpmaxconcurrentconnections " << "Maximum number of concurrent incoming TCP connections from clients" << "\n"; + output << "# TYPE " << frontsbase << "tcpmaxconcurrentconnections " << "counter" << "\n"; output << "# HELP " << frontsbase << "tcpavgqueriesperconnection " << "The average number of queries per TCP connection" << "\n"; output << "# TYPE " << frontsbase << "tcpavgqueriesperconnection " << "gauge" << "\n"; output << "# HELP " << frontsbase << "tcpavgconnectionduration " << "The average duration of a TCP connection (ms)" << "\n"; @@ -584,6 +589,7 @@ static void handlePrometheus(const YaHTTP::Request& req, YaHTTP::Response& resp) output << frontsbase << "tcpclientimeouts" << label << front->tcpClientTimeouts.load() << "\n"; output << frontsbase << "tcpdownstreamtimeouts" << label << front->tcpDownstreamTimeouts.load() << "\n"; output << frontsbase << "tcpcurrentconnections" << label << front->tcpCurrentConnections.load() << "\n"; + output << frontsbase << "tcpmaxconcurrentconnections" << label << front->tcpMaxConcurrentConnections.load() << "\n"; output << frontsbase << "tcpavgqueriesperconnection" << label << front->tcpAvgQueriesPerConnection.load() << "\n"; output << frontsbase << "tcpavgconnectionduration" << label << front->tcpAvgConnectionDuration.load() << "\n"; if (front->hasTLS()) { @@ -909,6 +915,7 @@ static void handleStats(const YaHTTP::Request& req, YaHTTP::Response& resp) {"tcpReadTimeouts", (double)a->tcpReadTimeouts}, {"tcpWriteTimeouts", (double)a->tcpWriteTimeouts}, {"tcpCurrentConnections", (double)a->tcpCurrentConnections}, + {"tcpMaxConcurrentConnections", (double)a->tcpMaxConcurrentConnections}, {"tcpNewConnections", (double)a->tcpNewConnections}, {"tcpReusedConnections", (double)a->tcpReusedConnections}, {"tcpAvgQueriesPerConnection", (double)a->tcpAvgQueriesPerConnection}, @@ -943,6 +950,7 @@ static void handleStats(const YaHTTP::Request& req, YaHTTP::Response& resp) { "tcpClientTimeouts", (double) front->tcpClientTimeouts }, { "tcpDownstreamTimeouts", (double) front->tcpDownstreamTimeouts }, { "tcpCurrentConnections", (double) front->tcpCurrentConnections }, + { "tcpMaxConcurrentConnections", (double) front->tcpMaxConcurrentConnections }, { "tcpAvgQueriesPerConnection", (double) front->tcpAvgQueriesPerConnection }, { "tcpAvgConnectionDuration", (double) front->tcpAvgConnectionDuration }, { "tlsNewSessions", (double) front->tlsNewSessions }, diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index b008212ae0..434647a3df 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -736,7 +736,10 @@ struct ClientState stat_t tcpGaveUp{0}; stat_t tcpClientTimeouts{0}; stat_t tcpDownstreamTimeouts{0}; + /* current number of connections to this frontend */ stat_t tcpCurrentConnections{0}; + /* maximum number of concurrent connections to this frontend */ + stat_t tcpMaxConcurrentConnections{0}; stat_t tlsNewSessions{0}; // A new TLS session has been negotiated, no resumption stat_t tlsResumptions{0}; // A TLS session has been resumed, either via session id or via a TLS ticket stat_t tlsUnknownTicketKey{0}; // A TLS ticket has been presented but we don't have the associated key (might have expired) @@ -907,7 +910,10 @@ struct DownstreamState stat_t tcpReadTimeouts{0}; stat_t tcpWriteTimeouts{0}; stat_t tcpConnectTimeouts{0}; + /* current number of connections to this backend */ stat_t tcpCurrentConnections{0}; + /* maximum number of concurrent connections to this backend */ + stat_t tcpMaxConcurrentConnections{0}; stat_t tcpReusedConnections{0}; stat_t tcpNewConnections{0}; pdns::stat_t_trait tcpAvgQueriesPerConnection{0.0}; diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index fd9cd78535..9436c881b0 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -352,6 +352,9 @@ bool TCPConnectionToBackend::reconnect() d_handler = std::move(handler); ++d_ds->tcpCurrentConnections; + if (d_ds->tcpCurrentConnections > d_ds->tcpMaxConcurrentConnections) { + d_ds->tcpMaxConcurrentConnections = d_ds->tcpCurrentConnections; + } return true; } catch (const std::runtime_error& e) { diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index 682f626940..cfcd23e0fb 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -1194,7 +1194,11 @@ static void on_accept(h2o_socket_t *listener, const char *err) sock->on_close.data = &conn; sock->data = dsc; - ++dsc->cs->tcpCurrentConnections; + auto concurrentConnections = ++dsc->cs->tcpCurrentConnections; + if (concurrentConnections > dsc->cs->tcpMaxConcurrentConnections) { + dsc->cs->tcpMaxConcurrentConnections = concurrentConnections; + } + ++dsc->df->d_httpconnects; h2o_accept(conn.d_acceptCtx->get(), sock);