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 #if defined( SLAPD_MONITOR_DN )
27 monitor_info( Connection *conn, Operation *op )
32 struct berval *vals[2];
33 int nconns, nwritewaiters, nreadwaiters;
45 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
46 /* initialize reader/writer lock */
48 e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
49 e->e_ndn = dn_normalize_case( ch_strdup(SLAPD_MONITOR_DN) );
52 val.bv_val = (char *) Versionstr;
53 if (( p = strchr( Versionstr, '\n' )) == NULL ) {
54 val.bv_len = strlen( Versionstr );
56 val.bv_len = p - Versionstr;
58 attr_merge( e, "version", vals );
60 ldap_pvt_thread_mutex_lock( &active_threads_mutex );
61 sprintf( buf, "%d", active_threads );
62 ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
64 val.bv_len = strlen( buf );
65 attr_merge( e, "threads", vals );
71 /* loop through the connections */
72 for ( c = connection_first( &connindex );
74 c = connection_next( c, &connindex ))
77 if ( c->c_writewaiter ) {
80 if ( c->c_currentber != NULL ) {
84 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
85 #ifndef LDAP_LOCALTIME
86 ltm = gmtime( &c->c_starttime );
87 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
89 ltm = gmtime( &c->c_activitytime );
90 strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
92 ltm = localtime( &c->.c_starttime );
93 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
95 ltm = localtime( &c->c_activitytime );
96 strftime( buf3, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
99 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
110 (long) c->c_protocol,
112 c->c_n_ops_received, c->c_n_ops_executing,
113 c->c_n_ops_pending, c->c_n_ops_completed,
115 /* add low-level counters here */
116 c->c_n_get, c->c_n_read, c->c_n_write,
118 c->c_currentber ? "r" : "",
119 c->c_writewaiter ? "w" : "",
120 c->c_ops != NULL ? "x" : "",
121 c->c_pending_ops != NULL ? "p" : "",
123 c->c_cdn ? c->c_cdn : "<anonymous>",
124 c->c_client_addr ? c->c_client_addr : "unknown",
125 c->c_client_name ? c->c_client_name : "unknown",
132 val.bv_len = strlen( buf );
133 attr_merge( e, "connection", vals );
137 sprintf( buf, "%d", nconns );
139 val.bv_len = strlen( buf );
140 attr_merge( e, "currentconnections", vals );
142 sprintf( buf, "%ld", connections_nextid() );
144 val.bv_len = strlen( buf );
145 attr_merge( e, "totalconnections", vals );
147 sprintf( buf, "%ld", (long) dtblsize );
149 val.bv_len = strlen( buf );
150 attr_merge( e, "dtablesize", vals );
152 sprintf( buf, "%d", nwritewaiters );
154 val.bv_len = strlen( buf );
155 attr_merge( e, "writewaiters", vals );
157 sprintf( buf, "%d", nreadwaiters );
159 val.bv_len = strlen( buf );
160 attr_merge( e, "readwaiters", vals );
162 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
163 sprintf( buf, "%ld", num_ops_initiated );
164 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
166 val.bv_len = strlen( buf );
167 attr_merge( e, "opsinitiated", vals );
169 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
170 sprintf( buf, "%ld", num_ops_completed );
171 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
173 val.bv_len = strlen( buf );
174 attr_merge( e, "opscompleted", vals );
176 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
177 sprintf( buf, "%ld", num_entries_sent );
178 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
180 val.bv_len = strlen( buf );
181 attr_merge( e, "entriessent", vals );
183 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
184 sprintf( buf, "%ld", num_bytes_sent );
185 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
187 val.bv_len = strlen( buf );
188 attr_merge( e, "bytessent", vals );
190 currenttime = slap_get_time();
192 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
193 #ifndef LDAP_LOCALTIME
194 ltm = gmtime( ¤ttime );
195 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
197 ltm = localtime( ¤ttime );
198 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
201 val.bv_len = strlen( buf );
202 attr_merge( e, "currenttime", vals );
204 #ifndef LDAP_LOCALTIME
205 ltm = gmtime( &starttime );
206 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
208 ltm = localtime( &starttime );
209 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
211 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
214 val.bv_len = strlen( buf );
215 attr_merge( e, "starttime", vals );
217 sprintf( buf, "%d", nbackends );
219 val.bv_len = strlen( buf );
220 attr_merge( e, "nbackends", vals );
222 #ifdef HAVE_THREAD_CONCURRENCY
223 sprintf( buf, "%d", ldap_pvt_thread_get_concurrency() );
225 val.bv_len = strlen( buf );
226 attr_merge( e, "concurrency", vals );
229 send_search_entry( &backends[0], conn, op, e, NULL, 0 );
230 send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
235 #endif /* slapd_monitor_dn */