]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Added TCP high-water statistics variable
authorDiego Fronza <diego@isc.org>
Tue, 5 Nov 2019 20:48:47 +0000 (17:48 -0300)
committerOndřej Surý <ondrej@sury.org>
Wed, 6 Nov 2019 11:54:40 +0000 (12:54 +0100)
This variable will report the maximum number of simultaneous tcp clients
that BIND has served while running.

It can be verified by running rndc status, then inspect "tcp high-water:
count", or by generating statistics file, rndc stats, then inspect the
line with "TCP connection high-water" text.

The tcp-highwater variable is atomically updated based on an existing
tcp-quota system handled in ns/client.c.

(cherry picked from commit 66fe8627de2c8488b7808c7b342e6ceb51f65414)

bin/named/client.c
bin/named/include/named/server.h
bin/named/server.c
bin/named/statschannel.c
lib/isc/stats.c

index 7b528860f79a5bed434656e2d3cdcdb9cd7645d6..15b3c8cdc058890bdabe01b438c0ad8d9482f8c0 100644 (file)
@@ -3507,7 +3507,6 @@ client_accept(ns_client_t *client) {
        isc_result_t result;
 
        CTRACE("accept");
-
        /*
         * Set up a new TCP connection. This means try to attach to the
         * TCP client quota (tcp-clients), but fail if we're over quota.
@@ -3558,6 +3557,12 @@ client_accept(ns_client_t *client) {
                RUNTIME_CHECK(result == ISC_R_SUCCESS);
        }
 
+       /* TCP high-water stats update. */
+       unsigned int curr_tcpquota = isc_quota_getused(&ns_g_server->tcpquota);
+       isc_stats_update_if_greater(ns_g_server->nsstats,
+                                   dns_nsstatscounter_tcphighwater,
+                                   curr_tcpquota);
+
        /*
         * If this client was set up using get_client() or get_worker(),
         * then TCP is already marked active. However, if it was restarted
index f5ed2b75f69cbb9dc7039804e8ee06eab41e3cdd..7ee8f66d28a90d76ca1c1a60e63df9fbaa1d36da 100644 (file)
@@ -220,7 +220,9 @@ enum {
 
        dns_nsstatscounter_keytagopt = 56,
 
-       dns_nsstatscounter_max = 57
+       dns_nsstatscounter_tcphighwater = 57,
+
+       dns_nsstatscounter_max = 58
 };
 
 /*%
index e0ac11dda02ee4d7fc2e66ef03a381c8a786bc2f..417e8a8dd691ac6a4d8d2bdd01b5a86e9f9d45dd 100644 (file)
@@ -10880,6 +10880,11 @@ ns_server_status(ns_server_t *server, isc_buffer_t **text) {
                     server->tcpquota.used, server->tcpquota.max);
        CHECK(putstr(text, line));
 
+       snprintf(line, sizeof(line), "TCP high-water: %" PRIu64 "\n",
+                isc_stats_get_counter(ns_g_server->nsstats,
+                                      dns_nsstatscounter_tcphighwater));
+       CHECK(putstr(text, line));
+
        CHECK(putstr(text, "server is up and running"));
        CHECK(putnull(text));
 
index 7e9ba43a735ea2de6740ea46a1f407087fd427f8..4cdf7d6fb66e9a2f0743c31be46cfd2e9030ea5e 100644 (file)
@@ -227,6 +227,8 @@ init_desc(void) {
        SET_NSSTATDESC(invalidsig, "requests with invalid signature",
                       "ReqBadSIG");
        SET_NSSTATDESC(requesttcp, "TCP requests received", "ReqTCP");
+       SET_NSSTATDESC(tcphighwater, "TCP connection high-water",
+                      "TCPConnHighWater");
        SET_NSSTATDESC(authrej, "auth queries rejected", "AuthQryRej");
        SET_NSSTATDESC(recurserej, "recursive queries rejected", "RecQryRej");
        SET_NSSTATDESC(xfrrej, "transfer requests rejected", "XfrRej");
index 72ee5028ab31cdd6328e2738d0ccf607ae89ea88..a03daf6a3b22ab9de7236246d6eeecb44916fdee 100644 (file)
@@ -474,7 +474,7 @@ void isc_stats_update_if_greater(isc_stats_t *stats,
 #endif
 
 #if ISC_STATS_USEMULTIFIELDS
-       uint64_t curr_value = (stats->counters[counter].hi << 32) &&
+       uint64_t curr_value = ((uint64_t)stats->counters[counter].hi << 32) &&
                stats->counters[counter].lo;
 
        if (curr_value < value) {
@@ -498,11 +498,12 @@ void isc_stats_update_if_greater(isc_stats_t *stats,
                                                 (int64_t *)&curr_value,
                                                 value));
 #else
-       isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_write);
+       /* This is not exactly thread safe, but we are ok with that on
+        * platforms without stdatomic support.
+        */
        if (stats->counters[counter] < value) {
                stats->counters[counter] = value;
        }
-       isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_write);
 #endif
 
 #if ISC_STATS_LOCKCOUNTERS
@@ -523,7 +524,7 @@ isc_stats_get_counter(isc_stats_t *stats, isc_statscounter_t counter)
 #endif
 
 #if ISC_STATS_USEMULTIFIELDS
-       curr_value = (stats->counters[counter].hi << 32) &&
+       curr_value = ((uint64_t)stats->counters[counter].hi << 32) &&
                stats->counters[counter].lo;
 #elif ISC_STATS_HAVEATOMICQ
 #if defined(ISC_STATS_HAVESTDATOMICQ)