2 * Copyright (c) 1995 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
17 #include <ac/socket.h>
18 #include <ac/string.h>
21 #include "ldap_defaults.h"
24 char *supportedControls[] = {
28 char *supportedExtensions[] = {
32 #if defined( SLAPD_MONITOR_DN )
35 monitor_info( Connection *conn, Operation *op )
40 struct berval *vals[2];
41 int nconns, nwritewaiters, nreadwaiters;
53 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
54 /* initialize reader/writer lock */
56 e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
57 e->e_ndn = dn_normalize_case( ch_strdup(SLAPD_MONITOR_DN) );
60 val.bv_val = (char *) Versionstr;
61 if (( p = strchr( Versionstr, '\n' )) == NULL ) {
62 val.bv_len = strlen( Versionstr );
64 val.bv_len = p - Versionstr;
66 attr_merge( e, "version", vals );
68 ldap_pvt_thread_mutex_lock( &active_threads_mutex );
69 sprintf( buf, "%d", active_threads );
70 ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
72 val.bv_len = strlen( buf );
73 attr_merge( e, "threads", vals );
79 /* loop through the connections */
80 for ( c = connection_first( &connindex );
82 c = connection_next( c, &connindex ))
85 if ( c->c_writewaiter ) {
88 if ( c->c_currentber != NULL ) {
92 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
93 #ifndef LDAP_LOCALTIME
94 ltm = gmtime( &c->c_starttime );
95 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
97 ltm = gmtime( &c->c_activitytime );
98 strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
100 ltm = localtime( &c->.c_starttime );
101 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
103 ltm = localtime( &c->c_activitytime );
104 strftime( buf3, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
107 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
118 (long) c->c_protocol,
120 c->c_n_ops_received, c->c_n_ops_executing,
121 c->c_n_ops_pending, c->c_n_ops_completed,
123 /* add low-level counters here */
124 c->c_n_get, c->c_n_read, c->c_n_write,
126 c->c_currentber ? "r" : "",
127 c->c_writewaiter ? "w" : "",
128 c->c_ops != NULL ? "x" : "",
129 c->c_pending_ops != NULL ? "p" : "",
131 c->c_cdn ? c->c_cdn : "<anonymous>",
132 c->c_client_addr ? c->c_client_addr : "unknown",
133 c->c_client_name ? c->c_client_name : "unknown",
140 val.bv_len = strlen( buf );
141 attr_merge( e, "connection", vals );
145 sprintf( buf, "%d", nconns );
147 val.bv_len = strlen( buf );
148 attr_merge( e, "currentconnections", vals );
150 sprintf( buf, "%ld", connections_nextid() );
152 val.bv_len = strlen( buf );
153 attr_merge( e, "totalconnections", vals );
155 sprintf( buf, "%ld", (long) dtblsize );
157 val.bv_len = strlen( buf );
158 attr_merge( e, "dtablesize", vals );
160 sprintf( buf, "%d", nwritewaiters );
162 val.bv_len = strlen( buf );
163 attr_merge( e, "writewaiters", vals );
165 sprintf( buf, "%d", nreadwaiters );
167 val.bv_len = strlen( buf );
168 attr_merge( e, "readwaiters", vals );
170 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
171 sprintf( buf, "%ld", num_ops_initiated );
172 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
174 val.bv_len = strlen( buf );
175 attr_merge( e, "opsinitiated", vals );
177 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
178 sprintf( buf, "%ld", num_ops_completed );
179 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
181 val.bv_len = strlen( buf );
182 attr_merge( e, "opscompleted", vals );
184 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
185 sprintf( buf, "%ld", num_entries_sent );
186 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
188 val.bv_len = strlen( buf );
189 attr_merge( e, "entriessent", vals );
191 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
192 sprintf( buf, "%ld", num_bytes_sent );
193 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
195 val.bv_len = strlen( buf );
196 attr_merge( e, "bytessent", vals );
198 currenttime = slap_get_time();
200 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
201 #ifndef LDAP_LOCALTIME
202 ltm = gmtime( ¤ttime );
203 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
205 ltm = localtime( ¤ttime );
206 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
209 val.bv_len = strlen( buf );
210 attr_merge( e, "currenttime", vals );
212 #ifndef LDAP_LOCALTIME
213 ltm = gmtime( &starttime );
214 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
216 ltm = localtime( &starttime );
217 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
219 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
222 val.bv_len = strlen( buf );
223 attr_merge( e, "starttime", vals );
225 sprintf( buf, "%d", nbackends );
227 val.bv_len = strlen( buf );
228 attr_merge( e, "nbackends", vals );
230 #ifdef HAVE_THREAD_CONCURRENCY
231 sprintf( buf, "%d", ldap_pvt_thread_get_concurrency() );
233 val.bv_len = strlen( buf );
234 attr_merge( e, "concurrency", vals );
237 send_search_entry( &backends[0], conn, op, e, NULL, 0 );
238 send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
243 #endif /* slapd_monitor_dn */