]> 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>
Wed, 17 Jan 2024 08:11:12 +0000 (11:11 +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.

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

index 94c97da1e1cb9f80c008ed6a8a2dbdb1197f86bb..83d420f65f1ffb86cd834403145ed3a3a1617fb6 100644 (file)
@@ -611,6 +611,10 @@ init_desc(void) {
        SET_SOCKSTATDESC(udp6active, "UDP/IPv6 sockets active", "UDP6Active");
        SET_SOCKSTATDESC(tcp4active, "TCP/IPv4 sockets active", "TCP4Active");
        SET_SOCKSTATDESC(tcp6active, "TCP/IPv6 sockets active", "TCP6Active");
+       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 3cc60b0644655ccb9257e267f1998d9aaee8a9af..23a076eba9784f03ff938751876133e71bde9dac 100644 (file)
@@ -77,6 +77,9 @@ enum {
        isc_sockstatscounter_tcp4active,
        isc_sockstatscounter_tcp6active,
 
+       isc_sockstatscounter_tcp4clients,
+       isc_sockstatscounter_tcp6clients,
+
        isc_sockstatscounter_max,
 };
 
index 71822b36411854e67c9da6c5c9680009a3c7ea75..9363119d3ef55730f9aaf8927bdd0d19b01d2125 100644 (file)
@@ -386,7 +386,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;
 
 typedef struct isc_nmsocket_tls_send_req {
index 41541cbb28dd5e10a0a3faa99dd964bb6ce7e02d..ea1c561a6221a430094f8e5fed4199cb1825593a 100644 (file)
@@ -63,7 +63,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[] = {
@@ -77,7 +78,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[] = {
@@ -86,7 +88,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[] = {
@@ -95,7 +97,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,
 };
 
 static void
index f7fe1a415b85b15a254b8339f2c34e0d21e9cbd5..b6545a912d1cc7e06a3269de291a58d16d040abc 100644 (file)
@@ -855,6 +855,10 @@ accept_connection(isc_nmsocket_t *csock) {
        UV_RUNTIME_CHECK(uv_timer_init, r);
        uv_handle_set_data((uv_handle_t *)&csock->read_timer, csock);
 
+       if (csock->server->pquota != NULL) {
+               isc__nm_incstats(csock, STATID_CLIENTS);
+       }
+
        /*
         * We need to initialize the tcp and timer before failing because
         * isc__nm_tcp_close() can't handle uninitalized TCP nmsocket.
@@ -1105,6 +1109,7 @@ tcp_close_sock(isc_nmsocket_t *sock) {
 
        if (sock->server != NULL) {
                if (sock->server->pquota != NULL) {
+                       isc__nm_decstats(sock, STATID_CLIENTS);
                        isc_quota_release(sock->server->pquota);
                }
                isc__nmsocket_detach(&sock->server);