1998-08-09 08:43:13 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that this notice is preserved and that due credit is given
|
|
|
|
* to the University of Michigan at Ann Arbor. The name of the University
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission. This software
|
|
|
|
* is provided ``as is'' without express or implied warranty.
|
|
|
|
*/
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
1999-06-17 11:54:25 +08:00
|
|
|
#include "ldap_defaults.h"
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include "slap.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#if defined( SLAPD_MONITOR_DN )
|
|
|
|
|
|
|
|
void
|
1999-07-24 11:39:23 +08:00
|
|
|
monitor_info(
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
char ** attrs,
|
|
|
|
int attrsonly )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
Entry *e;
|
1999-04-14 23:13:10 +08:00
|
|
|
char buf[BUFSIZ];
|
1998-08-09 08:43:13 +08:00
|
|
|
struct berval val;
|
|
|
|
struct berval *vals[2];
|
1999-04-14 23:13:10 +08:00
|
|
|
int nconns, nwritewaiters, nreadwaiters;
|
1998-08-09 08:43:13 +08:00
|
|
|
struct tm *ltm;
|
1999-03-09 15:15:35 +08:00
|
|
|
char *p;
|
1999-06-30 10:50:40 +08:00
|
|
|
char buf2[22];
|
|
|
|
char buf3[22];
|
1999-03-22 15:14:54 +08:00
|
|
|
Connection *c;
|
1999-05-27 13:52:38 +08:00
|
|
|
int connindex;
|
1999-04-14 23:13:10 +08:00
|
|
|
time_t currenttime;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
vals[0] = &val;
|
|
|
|
vals[1] = NULL;
|
|
|
|
|
|
|
|
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
|
1998-09-21 04:22:46 +08:00
|
|
|
/* initialize reader/writer lock */
|
1998-08-09 08:43:13 +08:00
|
|
|
e->e_attrs = NULL;
|
1998-11-28 04:21:54 +08:00
|
|
|
e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
|
1999-07-23 01:14:42 +08:00
|
|
|
e->e_ndn = ch_strdup(SLAPD_MONITOR_DN);
|
|
|
|
(void) dn_normalize_case( e->e_ndn );
|
1999-02-11 02:28:25 +08:00
|
|
|
e->e_private = NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-24 11:39:23 +08:00
|
|
|
{
|
|
|
|
char *rdn = ch_strdup( SLAPD_MONITOR_DN );
|
|
|
|
val.bv_val = strchr( rdn, '=' );
|
|
|
|
|
|
|
|
if( val.bv_val != NULL ) {
|
|
|
|
*val.bv_val = '\0';
|
|
|
|
val.bv_len = strlen( ++val.bv_val );
|
|
|
|
|
|
|
|
attr_merge( e, rdn, vals );
|
|
|
|
}
|
|
|
|
|
|
|
|
free( rdn );
|
|
|
|
}
|
|
|
|
|
1999-04-29 04:39:40 +08:00
|
|
|
val.bv_val = (char *) Versionstr;
|
1998-08-09 08:43:13 +08:00
|
|
|
if (( p = strchr( Versionstr, '\n' )) == NULL ) {
|
|
|
|
val.bv_len = strlen( Versionstr );
|
|
|
|
} else {
|
|
|
|
val.bv_len = p - Versionstr;
|
|
|
|
}
|
|
|
|
attr_merge( e, "version", vals );
|
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &active_threads_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
sprintf( buf, "%d", active_threads );
|
1999-03-22 15:14:54 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
|
|
|
attr_merge( e, "threads", vals );
|
|
|
|
|
|
|
|
nconns = 0;
|
|
|
|
nwritewaiters = 0;
|
|
|
|
nreadwaiters = 0;
|
1998-08-09 10:28:45 +08:00
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
/* loop through the connections */
|
1999-05-27 13:52:38 +08:00
|
|
|
for ( c = connection_first( &connindex );
|
|
|
|
c != NULL;
|
|
|
|
c = connection_next( c, &connindex ))
|
|
|
|
{
|
1999-03-22 15:14:54 +08:00
|
|
|
nconns++;
|
|
|
|
if ( c->c_writewaiter ) {
|
|
|
|
nwritewaiters++;
|
|
|
|
}
|
|
|
|
if ( c->c_currentber != NULL ) {
|
|
|
|
nreadwaiters++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
1998-10-22 03:35:30 +08:00
|
|
|
#ifndef LDAP_LOCALTIME
|
1999-03-22 15:14:54 +08:00
|
|
|
ltm = gmtime( &c->c_starttime );
|
|
|
|
strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
|
1999-06-19 06:54:19 +08:00
|
|
|
|
1999-06-30 10:50:40 +08:00
|
|
|
ltm = gmtime( &c->c_activitytime );
|
|
|
|
strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
|
1998-09-16 16:33:34 +08:00
|
|
|
#else
|
1999-03-22 15:14:54 +08:00
|
|
|
ltm = localtime( &c->.c_starttime );
|
|
|
|
strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
|
1999-06-19 06:54:19 +08:00
|
|
|
|
1999-06-30 10:50:40 +08:00
|
|
|
ltm = localtime( &c->c_activitytime );
|
1999-06-19 06:54:19 +08:00
|
|
|
strftime( buf3, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
|
1998-09-16 16:33:34 +08:00
|
|
|
#endif
|
1999-06-19 06:54:19 +08:00
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
|
|
|
|
1999-06-30 10:50:40 +08:00
|
|
|
sprintf( buf,
|
|
|
|
"%ld : %ld "
|
|
|
|
": %ld/%ld/%ld/%ld "
|
|
|
|
": %ld/%ld/%ld "
|
1999-07-03 03:48:07 +08:00
|
|
|
": %s%s%s%s%s%s "
|
1999-06-30 10:50:40 +08:00
|
|
|
": %s : %s : %s "
|
1999-07-22 04:54:23 +08:00
|
|
|
": %s : %s : %s : %s ",
|
1999-06-30 10:50:40 +08:00
|
|
|
|
|
|
|
c->c_connid,
|
|
|
|
(long) c->c_protocol,
|
|
|
|
|
|
|
|
c->c_n_ops_received, c->c_n_ops_executing,
|
|
|
|
c->c_n_ops_pending, c->c_n_ops_completed,
|
|
|
|
|
|
|
|
/* add low-level counters here */
|
|
|
|
c->c_n_get, c->c_n_read, c->c_n_write,
|
|
|
|
|
|
|
|
c->c_currentber ? "r" : "",
|
|
|
|
c->c_writewaiter ? "w" : "",
|
|
|
|
c->c_ops != NULL ? "x" : "",
|
|
|
|
c->c_pending_ops != NULL ? "p" : "",
|
1999-07-03 03:48:07 +08:00
|
|
|
connection_state2str( c->c_conn_state ),
|
|
|
|
c->c_bind_in_progress ? "S" : "",
|
1999-06-30 10:50:40 +08:00
|
|
|
|
|
|
|
c->c_cdn ? c->c_cdn : "<anonymous>",
|
1999-07-22 04:54:23 +08:00
|
|
|
|
|
|
|
c->c_listener_url,
|
|
|
|
c->c_peer_domain,
|
|
|
|
c->c_peer_name,
|
|
|
|
c->c_sock_name,
|
1999-06-30 10:50:40 +08:00
|
|
|
|
|
|
|
buf2,
|
1999-06-19 06:54:19 +08:00
|
|
|
buf3
|
1999-03-22 15:14:54 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
|
|
|
attr_merge( e, "connection", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-03-22 15:14:54 +08:00
|
|
|
connection_done(c);
|
1998-08-09 10:28:45 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
sprintf( buf, "%d", nconns );
|
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
1999-07-16 10:45:46 +08:00
|
|
|
attr_merge( e, "currentConnections", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
sprintf( buf, "%ld", connections_nextid() );
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
1999-07-16 10:45:46 +08:00
|
|
|
attr_merge( e, "totalConnections", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
sprintf( buf, "%ld", (long) dtblsize );
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
1999-07-16 10:45:46 +08:00
|
|
|
attr_merge( e, "dTableSize", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
sprintf( buf, "%d", nwritewaiters );
|
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
1999-07-16 10:45:46 +08:00
|
|
|
attr_merge( e, "writeWaiters", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
sprintf( buf, "%d", nreadwaiters );
|
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
1999-07-16 10:45:46 +08:00
|
|
|
attr_merge( e, "readWaiters", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-26 10:51:33 +08:00
|
|
|
ldap_pvt_thread_mutex_lock(&num_ops_mutex);
|
|
|
|
sprintf( buf, "%ld", num_ops_initiated );
|
|
|
|
ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
1999-07-16 10:45:46 +08:00
|
|
|
attr_merge( e, "opsInitiated", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-26 10:51:33 +08:00
|
|
|
ldap_pvt_thread_mutex_lock(&num_ops_mutex);
|
|
|
|
sprintf( buf, "%ld", num_ops_completed );
|
|
|
|
ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
1999-07-16 10:45:46 +08:00
|
|
|
attr_merge( e, "opsCompleted", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-26 10:51:33 +08:00
|
|
|
ldap_pvt_thread_mutex_lock(&num_sent_mutex);
|
1998-08-09 08:43:13 +08:00
|
|
|
sprintf( buf, "%ld", num_entries_sent );
|
1999-03-26 10:51:33 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
1999-07-16 10:45:46 +08:00
|
|
|
attr_merge( e, "entriesSent", vals );
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock(&num_sent_mutex);
|
|
|
|
sprintf( buf, "%ld", num_refs_sent );
|
|
|
|
ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
|
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
|
|
|
attr_merge( e, "referencesSent", vals );
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock(&num_sent_mutex);
|
|
|
|
sprintf( buf, "%ld", num_pdu_sent );
|
|
|
|
ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
|
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
|
|
|
attr_merge( e, "pduSent", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-26 10:51:33 +08:00
|
|
|
ldap_pvt_thread_mutex_lock(&num_sent_mutex);
|
1998-08-09 08:43:13 +08:00
|
|
|
sprintf( buf, "%ld", num_bytes_sent );
|
1999-03-26 10:51:33 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
1999-07-16 10:45:46 +08:00
|
|
|
attr_merge( e, "bytesSent", vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
currenttime = slap_get_time();
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
1998-10-22 03:35:30 +08:00
|
|
|
#ifndef LDAP_LOCALTIME
|
1998-10-22 03:29:20 +08:00
|
|
|
ltm = gmtime( ¤ttime );
|
1998-09-16 16:33:34 +08:00
|
|
|
strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
|
|
|
|
#else
|
1998-10-22 03:29:20 +08:00
|
|
|
ltm = localtime( ¤ttime );
|
1998-09-16 16:33:34 +08:00
|
|
|
strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
|
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
|
|
|
attr_merge( e, "currenttime", vals );
|
|
|
|
|
1998-10-22 03:35:30 +08:00
|
|
|
#ifndef LDAP_LOCALTIME
|
1998-10-22 03:29:20 +08:00
|
|
|
ltm = gmtime( &starttime );
|
1998-09-16 16:33:34 +08:00
|
|
|
strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
|
|
|
|
#else
|
1998-10-22 03:29:20 +08:00
|
|
|
ltm = localtime( &starttime );
|
1998-09-16 16:33:34 +08:00
|
|
|
strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
|
|
|
|
#endif
|
1999-03-22 15:14:54 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
|
|
|
attr_merge( e, "starttime", vals );
|
|
|
|
|
|
|
|
sprintf( buf, "%d", nbackends );
|
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
|
|
|
attr_merge( e, "nbackends", vals );
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
#ifdef HAVE_THREAD_CONCURRENCY
|
1999-02-04 02:32:25 +08:00
|
|
|
sprintf( buf, "%d", ldap_pvt_thread_get_concurrency() );
|
1998-08-09 08:43:13 +08:00
|
|
|
val.bv_val = buf;
|
|
|
|
val.bv_len = strlen( buf );
|
|
|
|
attr_merge( e, "concurrency", vals );
|
|
|
|
#endif
|
|
|
|
|
1999-07-24 11:39:23 +08:00
|
|
|
val.bv_val = "top";
|
|
|
|
val.bv_len = sizeof("top")-1;
|
|
|
|
attr_merge( e, "objectClass", vals );
|
|
|
|
|
|
|
|
val.bv_val = "extensibleObject";
|
|
|
|
val.bv_len = sizeof("extensibleObject")-1;
|
|
|
|
attr_merge( e, "objectClass", vals );
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
send_search_entry( &backends[0], conn, op, e,
|
1999-07-24 11:39:23 +08:00
|
|
|
attrs, attrsonly, NULL );
|
1999-07-16 10:45:46 +08:00
|
|
|
send_search_result( conn, op, LDAP_SUCCESS,
|
|
|
|
NULL, NULL, NULL, NULL, 1 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
entry_free( e );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* slapd_monitor_dn */
|