]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9186 Add a counter to cn=Listener to track total number of established connection...
authorNadezhda Ivanova <nivanova@symas.com>
Mon, 28 Oct 2024 13:48:33 +0000 (15:48 +0200)
committerQuanah Gibson-Mount <quanah@openldap.org>
Mon, 16 Dec 2024 18:31:23 +0000 (18:31 +0000)
servers/slapd/back-monitor/back-monitor.h
servers/slapd/back-monitor/init.c
servers/slapd/back-monitor/listener.c
servers/slapd/connection.c
servers/slapd/daemon.c
servers/slapd/slap.h

index 30851afbb31e03abc3184d15441a19985ff1ac44..e6441f27db298aefa315180114cccf874ddc36b7 100644 (file)
@@ -140,6 +140,7 @@ typedef struct monitor_info_t {
        AttributeDescription    *mi_ad_monitorConnectionOpsAsync;
        AttributeDescription    *mi_ad_monitorLogLevel;
        AttributeDescription    *mi_ad_monitorDebugLevel;
+       AttributeDescription    *mi_ad_monitorTotalListenerConnections;
 
        /*
         * Generic description attribute
index 4749946a1d5a1f6d3d11b6c974ed560cd9c8c967..48e3e630d900b866353298fd09b51b07b76ba7af 100644 (file)
@@ -1954,6 +1954,13 @@ monitor_back_initialize(
                        "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
                        "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
                        offsetof(monitor_info_t, mi_ad_monitorDebugLevel) },
+               { "( 1.3.6.1.4.1.4203.666.1.55.34 "
+                       "NAME 'monitorTotalListenerConnections' "
+                       "DESC 'monitor total number established of connections per listener since startup' "
+                       "SUP monitorCounter "
+                       "NO-USER-MODIFICATION "
+                       "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
+                       offsetof(monitor_info_t, mi_ad_monitorTotalListenerConnections) },
                { NULL, 0, -1 }
        };
 
index 63ab3b90615e6c69455f1f129612952fe9093896..22ce6b95fa8c995112eb57ac80a09d799b9e73e7 100644 (file)
 #include "slap.h"
 #include "back-monitor.h"
 
+static int
+monitor_subsys_listener_update(
+       Operation               *op,
+       SlapReply               *rs,
+       Entry           *e )
+{
+       monitor_info_t  *mi = ( monitor_info_t * )op->o_bd->be_private;
+       int i;
+       Listener        **l;
+
+       assert( mi != NULL );
+       assert( e != NULL );
+
+       if ( ( l = slapd_get_listeners() ) == NULL ) {
+               if ( slapMode & SLAP_TOOL_MODE ) {
+                       return 0;
+               }
+
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_listener_update: "
+                       "unable to get listeners\n" );
+               return( -1 );
+       }
+
+       for ( i = 0; l[ i ]; i++ ) {
+               char            buf[ BACKMONITOR_BUFSIZE ];
+               struct berval   sl_bv;
+               struct berval           rdn;
+               dnRdn( &e->e_nname, &rdn );
+               sl_bv.bv_len = snprintf( buf, sizeof( buf ),
+                                                                "cn=listener %d", i );
+               sl_bv.bv_val = buf;
+               if ( dn_match( &rdn, &sl_bv ) ) {
+                       Attribute *a = attr_find( e->e_attrs, mi->mi_ad_monitorTotalListenerConnections );
+                       assert( a != NULL );
+                       UI2BV( &a->a_vals[ 0 ], l[ i ]->sl_n_conns_opened );
+               }
+       }
+}
+
 int
 monitor_subsys_listener_init(
        BackendDB               *be,
@@ -52,6 +92,8 @@ monitor_subsys_listener_init(
                return( -1 );
        }
 
+       ms->mss_update = monitor_subsys_listener_update;
+
        mi = ( monitor_info_t * )be->be_private;
 
        if ( monitor_cache_get( mi, &ms->mss_ndn, &e_listener ) ) {
@@ -87,6 +129,10 @@ monitor_subsys_listener_init(
                attr_merge_normalize_one( e, slap_schema.si_ad_labeledURI,
                                &l[ i ]->sl_url, NULL );
 
+               ber_str2bv( "0", STRLENOF( "0" ), 0, &bv );
+               attr_merge_normalize_one( e, mi->mi_ad_monitorTotalListenerConnections,
+                               &bv, NULL );
+
 #ifdef HAVE_TLS
                if ( l[ i ]->sl_is_tls ) {
                        struct berval bv;
index 717934b55e468c1f5692350fb884f0996445625d..2766b9419311202e84d1f149d2842de3a4398697 100644 (file)
@@ -537,6 +537,10 @@ Connection * connection_init(
        slapd_add_internal( s, 1 );
 
        backend_connection_init(c);
+
+       if ( c->c_listener )
+               ldap_pvt_mp_add_ulong(c->c_listener->sl_n_conns_opened, 1);
+
        ldap_pvt_thread_mutex_unlock( &c->c_mutex );
 
        if ( !(flags & CONN_IS_UDP ))
index 2b6d26c7ace7aa77ca45255341afd528ebf47afe..c08e560fcd1688956dece981624e7ba826cac04e 100644 (file)
@@ -1561,6 +1561,7 @@ slap_open_listener(
        l.sl_tcp_rmem = 0;
        l.sl_tcp_wmem = 0;
 #endif /* LDAP_TCP_BUFFER */
+       ldap_pvt_mp_init( l.sl_n_conns_opened );
 
        port = (unsigned short) lud->lud_port;
 
index d234ac54775e0c5ba55e3c47a85917f8ba92bb7e..d0d6d69395af31027571135f24a526abaedcdd38 100644 (file)
@@ -3046,6 +3046,7 @@ struct Listener {
        int     sl_tcp_rmem;    /* custom TCP read buffer size */
        int     sl_tcp_wmem;    /* custom TCP write buffer size */
 #endif
+       ldap_pvt_mp_t sl_n_conns_opened; /* total number of connections opened since startup */
 };
 
 /*