]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add 'max concurrent connections' counters
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 22 Mar 2021 16:12:46 +0000 (17:12 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 26 Mar 2021 09:52:23 +0000 (10:52 +0100)
pdns/dnsdist-carbon.cc
pdns/dnsdist-lua-inspection.cc
pdns/dnsdist-tcp.cc
pdns/dnsdist-web.cc
pdns/dnsdist.hh
pdns/dnsdistdist/dnsdist-tcp-downstream.cc
pdns/dnsdistdist/doh.cc

index db0dd411df69583718390531c5e11264eccf9822..9d973b454b44292d894bfb0e693cebb52fe6f63a 100644 (file)
@@ -104,6 +104,7 @@ void carbonDumpThread()
             str<<base<<"tcpwritetimeouts" << ' '<< state->tcpWriteTimeouts.load() << " " << now << "\r\n";
             str<<base<<"tcpconnecttimeouts" << ' '<< state->tcpConnectTimeouts.load() << " " << now << "\r\n";
             str<<base<<"tcpcurrentconnections" << ' '<< state->tcpCurrentConnections.load() << " " << now << "\r\n";
+            str<<base<<"tcpmaxconcurrentconnections" << ' '<< state->tcpMaxConcurrentConnections.load() << " " << now << "\r\n";
             str<<base<<"tcpnewconnections" << ' '<< state->tcpNewConnections.load() << " " << now << "\r\n";
             str<<base<<"tcpreusedconnections" << ' '<< state->tcpReusedConnections.load() << " " << now << "\r\n";
             str<<base<<"tcpavgqueriesperconnection" << ' '<< state->tcpAvgQueriesPerConnection.load() << " " << now << "\r\n";
@@ -132,6 +133,7 @@ void carbonDumpThread()
             str<<base<<"tcpclientimeouts" << ' '<< front->tcpClientTimeouts.load() << " " << now << "\r\n";
             str<<base<<"tcpdownstreamtimeouts" << ' '<< front->tcpDownstreamTimeouts.load() << " " << now << "\r\n";
             str<<base<<"tcpcurrentconnections" << ' '<< front->tcpCurrentConnections.load() << " " << now << "\r\n";
+            str<<base<<"tcpmaxconcurrentconnections" << ' '<< front->tcpMaxConcurrentConnections.load() << " " << now << "\r\n";
             str<<base<<"tcpavgqueriesperconnection" << ' '<< front->tcpAvgQueriesPerConnection.load() << " " << now << "\r\n";
             str<<base<<"tcpavgconnectionduration" << ' '<< front->tcpAvgConnectionDuration.load() << " " << now << "\r\n";
             str<<base<<"tls10-queries" << ' ' << front->tls10queries.load() << " " << now << "\r\n";
index a21d38a47e095f29b2a06f3febf98b9244e47f30..f23430d643069ef443dccc85f7786b7a97622c15 100644 (file)
@@ -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;
       }
 
index cb11142a79ee7676d5d5cda6cd2f20dc90e28c44..19185d9d53c3d8e4d8207b878a3c42986674e9f2 100644 (file)
@@ -1231,7 +1231,10 @@ void tcpAcceptorThread(ClientState* cs)
       ci->fd = accept(cs->tcpFD, reinterpret_cast<struct sockaddr*>(&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());
index 05f280dfecc540758814dadb56e3a942e8cc38b6..9d31b3aefaef592dcf49c25fa2777c3c5e3e0c43 100644 (file)
@@ -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 },
index b008212ae0dfbcb613fa707e65c54e30eeb15e0f..434647a3dfa245c18edce6af20927416345f345d 100644 (file)
@@ -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<double> tcpAvgQueriesPerConnection{0.0};
index fd9cd78535b94da4864f893650131748b2cb2bff..9436c881b01da1a17da3d5ec8267788b96e75c0e 100644 (file)
@@ -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) {
index 682f62694058b8f578bd23297a6923a4e335b7e2..cfcd23e0fb8469cb9f631dc6df28194b94339f6b 100644 (file)
@@ -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);