]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Expose the TCP client count in statistics channel
authorAydın Mercan <aydin@isc.org>
Tue, 2 Jan 2024 13:28:46 +0000 (16:28 +0300)
committerAydın Mercan <aydin@isc.org>
Tue, 27 Feb 2024 08:04:28 +0000 (11:04 +0300)
The statistics channel does not expose the current number of TCP clients
connected, only the highwater. Therefore, users did not have an easy
means to collect statistics about TCP clients served over time. This
information could only be measured as a seperate mechanism via rndc by
looking at the TCP quota filled.

In order to expose the exact current count of connected TCP clients
(tracked by the "tcp-clients" quota) as a statistics counter, an
extra, dedicated Network Manager callback would need to be
implemented for that purpose (a counterpart of ns__client_tcpconn()
that would be run when a TCP connection is torn down), which is
inefficient. Instead, track the number of currently-connected TCP
clients separately for IPv4 and IPv6, as Network Manager statistics.

(cherry picked from commit 2690dc48d357c85c59f0d72063d7a799e9d03bc0)

bin/named/statschannel.c
lib/isc/include/isc/stats.h
lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tcpdns.c
lib/isc/netmgr/tlsdns.c

index 2c4760ca200f2191ca5469239499cca565d5eb25..0cb56b2e65c2397ba1afc05f9dc0f280eb6a56b0 100644 (file)
@@ -626,6 +626,11 @@ init_desc(void) {
        SET_SOCKSTATDESC(unixactive, "Unix domain sockets active",
                         "UnixActive");
        SET_SOCKSTATDESC(rawactive, "Raw sockets active", "RawActive");
+       SET_SOCKSTATDESC(tcp4clients, "TCP/IPv4 clients currently connected",
+                        "TCP4Clients");
+       SET_SOCKSTATDESC(tcp6clients, "TCP/IPv6 clients currently connected",
+                        "TCP6Clients");
+
        INSIST(i == isc_sockstatscounter_max);
 
        /* Initialize DNSSEC statistics */
index 5bed7d52852c6bbc771f0e277c7c87857b429150..187a1795df0bf3f9fa65d68f9876ce84ee1a4746 100644 (file)
@@ -100,7 +100,10 @@ enum {
        isc_sockstatscounter_rawrecvfail = 60,
        isc_sockstatscounter_rawactive = 61,
 
-       isc_sockstatscounter_max = 62
+       isc_sockstatscounter_tcp4clients = 62,
+       isc_sockstatscounter_tcp6clients = 63,
+
+       isc_sockstatscounter_max = 64
 };
 
 ISC_LANG_BEGINDECLS
index 6aca9ab92ca1f0f65e5ddd8202635650c19db317..da9e8c3a59f7ae16d9207ddae8bf1a18f84966de 100644 (file)
@@ -856,7 +856,8 @@ typedef enum {
        STATID_SENDFAIL = 8,
        STATID_RECVFAIL = 9,
        STATID_ACTIVE = 10,
-       STATID_MAX = 11,
+       STATID_CLIENTS = 11,
+       STATID_MAX = 12,
 } isc__nm_statid_t;
 
 #if HAVE_LIBNGHTTP2
index 2310b4b90434a607d11d8411ebb4089412f9e235..44ef28e360c59adabd0f43c304e63ce8d17c824f 100644 (file)
@@ -67,7 +67,8 @@ static const isc_statscounter_t udp4statsindex[] = {
        -1,
        isc_sockstatscounter_udp4sendfail,
        isc_sockstatscounter_udp4recvfail,
-       isc_sockstatscounter_udp4active
+       isc_sockstatscounter_udp4active,
+       -1,
 };
 
 static const isc_statscounter_t udp6statsindex[] = {
@@ -81,7 +82,8 @@ static const isc_statscounter_t udp6statsindex[] = {
        -1,
        isc_sockstatscounter_udp6sendfail,
        isc_sockstatscounter_udp6recvfail,
-       isc_sockstatscounter_udp6active
+       isc_sockstatscounter_udp6active,
+       -1,
 };
 
 static const isc_statscounter_t tcp4statsindex[] = {
@@ -90,7 +92,7 @@ static const isc_statscounter_t tcp4statsindex[] = {
        isc_sockstatscounter_tcp4connectfail, isc_sockstatscounter_tcp4connect,
        isc_sockstatscounter_tcp4acceptfail,  isc_sockstatscounter_tcp4accept,
        isc_sockstatscounter_tcp4sendfail,    isc_sockstatscounter_tcp4recvfail,
-       isc_sockstatscounter_tcp4active
+       isc_sockstatscounter_tcp4active,      isc_sockstatscounter_tcp4clients,
 };
 
 static const isc_statscounter_t tcp6statsindex[] = {
@@ -99,7 +101,7 @@ static const isc_statscounter_t tcp6statsindex[] = {
        isc_sockstatscounter_tcp6connectfail, isc_sockstatscounter_tcp6connect,
        isc_sockstatscounter_tcp6acceptfail,  isc_sockstatscounter_tcp6accept,
        isc_sockstatscounter_tcp6sendfail,    isc_sockstatscounter_tcp6recvfail,
-       isc_sockstatscounter_tcp6active
+       isc_sockstatscounter_tcp6active,      isc_sockstatscounter_tcp6clients,
 };
 
 #if 0
index b2a0b1016d2cf781fbaa94b2a7e97af20959397c..1864a45abac616feb75b4bace39bf462e0dc4eaa 100644 (file)
@@ -689,6 +689,7 @@ destroy:
         * chance to be executed.
         */
        if (sock->quota != NULL) {
+               isc__nm_decstats(sock, STATID_CLIENTS);
                isc_quota_detach(&sock->quota);
        }
 }
@@ -1004,6 +1005,8 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
        UV_RUNTIME_CHECK(uv_timer_init, r);
        uv_handle_set_data((uv_handle_t *)&csock->read_timer, csock);
 
+       isc__nm_incstats(csock, STATID_CLIENTS);
+
        r = uv_accept(&ssock->uv_handle.stream, &csock->uv_handle.stream);
        if (r != 0) {
                result = isc__nm_uverr2result(r);
@@ -1366,6 +1369,7 @@ tcpdns_close_direct(isc_nmsocket_t *sock) {
        REQUIRE(atomic_load(&sock->closing));
 
        if (sock->quota != NULL) {
+               isc__nm_decstats(sock, STATID_CLIENTS);
                isc_quota_detach(&sock->quota);
        }
 
index feeb1a8d7df83264f14d10c68d482ec9a1a18dec..7a005db9b90ac992a7db25d322b3d0cf4af97de7 100644 (file)
@@ -895,6 +895,7 @@ destroy:
         * had a chance to be executed.
         */
        if (sock->quota != NULL) {
+               isc__nm_decstats(sock, STATID_CLIENTS);
                isc_quota_detach(&sock->quota);
        }
 }
@@ -1628,6 +1629,8 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
        UV_RUNTIME_CHECK(uv_timer_init, r);
        uv_handle_set_data((uv_handle_t *)&csock->read_timer, csock);
 
+       isc__nm_incstats(csock, STATID_CLIENTS);
+
        r = uv_accept(&ssock->uv_handle.stream, &csock->uv_handle.stream);
        if (r != 0) {
                result = isc__nm_uverr2result(r);
@@ -2109,6 +2112,7 @@ tlsdns_close_direct(isc_nmsocket_t *sock) {
        REQUIRE(sock->tls.pending_req == NULL);
 
        if (sock->quota != NULL) {
+               isc__nm_decstats(sock, STATID_CLIENTS);
                isc_quota_detach(&sock->quota);
        }