openldap/servers/slapd/monitor.c

214 lines
5.4 KiB
C
Raw Normal View History

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>
1998-08-09 08:43:13 +08:00
#include "ldapconfig.h"
#include "slap.h"
1998-08-09 08:43:13 +08:00
#if defined( SLAPD_MONITOR_DN )
void
monitor_info( Connection *conn, Operation *op )
{
Entry *e;
char buf[BUFSIZ];
1998-08-09 08:43:13 +08:00
struct berval val;
struct berval *vals[2];
int nconns, nwritewaiters, nreadwaiters;
1998-08-09 08:43:13 +08:00
struct tm *ltm;
char *p;
#ifdef LDAP_COUNTERS
int i;
char buf2[22]
Connection *c;
int connindex;
#endif
time_t currenttime;
1998-08-09 08:43:13 +08:00
vals[0] = &val;
vals[1] = NULL;
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
/* initialize reader/writer lock */
1998-08-09 08:43:13 +08:00
e->e_attrs = NULL;
e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
1999-01-19 04:00:58 +08:00
e->e_ndn = dn_normalize_case( ch_strdup(SLAPD_MONITOR_DN) );
e->e_private = NULL;
1998-08-09 08:43:13 +08:00
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 );
ldap_pvt_thread_mutex_lock( &active_threads_mutex );
1998-08-09 08:43:13 +08:00
sprintf( buf, "%d", active_threads );
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;
#ifdef LDAP_COUNTERS
/* loop through the connections */
for ( c = connection_first( &connindex );
c != NULL;
c = connection_next( c, &connindex ))
{
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
ltm = gmtime( &c->c_starttime );
strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
#else
ltm = localtime( &c->.c_starttime );
strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
#endif
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
sprintf( buf, "%d : %s : %d : %d : %s : %s%s%s%s", i,
1999-03-26 10:51:33 +08:00
buf2, c[i].c_n_ops_received, c[i].c_n_ops_completed,
c[i].c_cdn ? c[i].c_cdn : "NULLDN",
1999-03-26 10:51:33 +08:00
c[i].c_currentber ? "r" : "",
c[i].c_writewaiter ? "w" : "",
1999-03-26 10:51:33 +08:00
c[i].c_ops != NULL ? "x" : "",
c[i].c_pending_ops != NULL ? "p" : ""
);
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "connection", vals );
1998-08-09 08:43:13 +08:00
}
connection_done(c);
#endif
1998-08-09 08:43:13 +08:00
sprintf( buf, "%d", nconns );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "currentconnections", vals );
sprintf( buf, "%ld", connections_nextid() );
1998-08-09 08:43:13 +08:00
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "totalconnections", vals );
sprintf( buf, "%d", dtblsize );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "dtablesize", vals );
sprintf( buf, "%d", nwritewaiters );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "writewaiters", vals );
sprintf( buf, "%d", nreadwaiters );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "readwaiters", vals );
#ifdef LDAP_COUNTERS
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 );
attr_merge( e, "opsinitiated", vals );
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 );
attr_merge( e, "opscompleted", vals );
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 );
attr_merge( e, "entriessent", vals );
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 );
attr_merge( e, "bytessent", vals );
#endif
1998-08-09 08:43:13 +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( &currenttime );
strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
#else
1998-10-22 03:29:20 +08:00
ltm = localtime( &currenttime );
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 );
strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
#else
1998-10-22 03:29:20 +08:00
ltm = localtime( &starttime );
strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
#endif
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 );
#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
send_search_entry( &backends[0], conn, op, e, NULL, 0 );
send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
entry_free( e );
}
#endif /* slapd_monitor_dn */