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 "ldapconfig.h"
24 #if defined( SLAPD_MONITOR_DN )
27 monitor_info( Connection *conn, Operation *op )
32 struct berval *vals[2];
33 int nconns, nwritewaiters, nreadwaiters;
46 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
47 /* initialize reader/writer lock */
49 e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
50 e->e_ndn = dn_normalize_case( ch_strdup(SLAPD_MONITOR_DN) );
53 val.bv_val = Versionstr;
54 if (( p = strchr( Versionstr, '\n' )) == NULL ) {
55 val.bv_len = strlen( Versionstr );
57 val.bv_len = p - Versionstr;
59 attr_merge( e, "version", vals );
61 ldap_pvt_thread_mutex_lock( &active_threads_mutex );
62 sprintf( buf, "%d", active_threads );
63 ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
65 val.bv_len = strlen( buf );
66 attr_merge( e, "threads", vals );
73 /* loop through the connections */
74 for ( c = connection_first() ; c != NULL; c = connection_next(c) ) {
76 if ( c->c_writewaiter ) {
79 if ( c->c_currentber != NULL ) {
83 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
84 #ifndef LDAP_LOCALTIME
85 ltm = gmtime( &c->c_starttime );
86 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
88 ltm = localtime( &c->.c_starttime );
89 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
91 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
93 sprintf( buf, "%d : %s : %d : %d : %s : %s%s%s%s", i,
94 buf2, c[i].c_n_ops_received, c[i].c_n_ops_completed,
95 c[i].c_cdn ? c[i].c_cdn : "NULLDN",
96 c[i].c_currentber ? "r" : "",
97 c[i].c_writewaiter ? "w" : "",
98 c[i].c_ops != NULL ? "x" : "",
99 c[i].c_pending_ops != NULL ? "p" : ""
103 val.bv_len = strlen( buf );
104 attr_merge( e, "connection", vals );
109 sprintf( buf, "%d", nconns );
111 val.bv_len = strlen( buf );
112 attr_merge( e, "currentconnections", vals );
114 sprintf( buf, "%ld", connections_nextid() );
116 val.bv_len = strlen( buf );
117 attr_merge( e, "totalconnections", vals );
119 sprintf( buf, "%d", dtblsize );
121 val.bv_len = strlen( buf );
122 attr_merge( e, "dtablesize", vals );
124 sprintf( buf, "%d", nwritewaiters );
126 val.bv_len = strlen( buf );
127 attr_merge( e, "writewaiters", vals );
129 sprintf( buf, "%d", nreadwaiters );
131 val.bv_len = strlen( buf );
132 attr_merge( e, "readwaiters", vals );
135 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
136 sprintf( buf, "%ld", num_ops_initiated );
137 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
139 val.bv_len = strlen( buf );
140 attr_merge( e, "opsinitiated", vals );
142 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
143 sprintf( buf, "%ld", num_ops_completed );
144 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
146 val.bv_len = strlen( buf );
147 attr_merge( e, "opscompleted", vals );
149 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
150 sprintf( buf, "%ld", num_entries_sent );
151 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
153 val.bv_len = strlen( buf );
154 attr_merge( e, "entriessent", vals );
156 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
157 sprintf( buf, "%ld", num_bytes_sent );
158 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
160 val.bv_len = strlen( buf );
161 attr_merge( e, "bytessent", vals );
164 currenttime = slap_get_time();
166 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
167 #ifndef LDAP_LOCALTIME
168 ltm = gmtime( ¤ttime );
169 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
171 ltm = localtime( ¤ttime );
172 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
175 val.bv_len = strlen( buf );
176 attr_merge( e, "currenttime", vals );
178 #ifndef LDAP_LOCALTIME
179 ltm = gmtime( &starttime );
180 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
182 ltm = localtime( &starttime );
183 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
185 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
188 val.bv_len = strlen( buf );
189 attr_merge( e, "starttime", vals );
191 sprintf( buf, "%d", nbackends );
193 val.bv_len = strlen( buf );
194 attr_merge( e, "nbackends", vals );
196 #ifdef HAVE_THREAD_CONCURRENCY
197 sprintf( buf, "%d", ldap_pvt_thread_get_concurrency() );
199 val.bv_len = strlen( buf );
200 attr_merge( e, "concurrency", vals );
203 send_search_entry( &backends[0], conn, op, e, NULL, 0 );
204 send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
209 #endif /* slapd_monitor_dn */