ITS#9186 Add a counter to cn=Listener to track total number of established connections since startup

This commit is contained in:
Nadezhda Ivanova 2024-10-28 15:48:33 +02:00 committed by Quanah Gibson-Mount
parent 70d8e22db7
commit e2b04c434e
6 changed files with 60 additions and 0 deletions

View 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

View 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 }
};

View File

@ -27,6 +27,46 @@
#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;

View 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 ))

View 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;

View 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 */
};
/*