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 )
30 char buf[BUFSIZ], buf2[22];
32 struct berval *vals[2];
33 int i, nconns, nwritewaiters, nreadwaiters;
42 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
43 /* initialize reader/writer lock */
45 e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
46 e->e_ndn = dn_normalize_case( ch_strdup(SLAPD_MONITOR_DN) );
49 val.bv_val = Versionstr;
50 if (( p = strchr( Versionstr, '\n' )) == NULL ) {
51 val.bv_len = strlen( Versionstr );
53 val.bv_len = p - Versionstr;
55 attr_merge( e, "version", vals );
57 ldap_pvt_thread_mutex_lock( &active_threads_mutex );
58 sprintf( buf, "%d", active_threads );
59 ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
61 val.bv_len = strlen( buf );
62 attr_merge( e, "threads", vals );
69 /* loop through the connections */
70 for ( c = connection_first() ; c != NULL; c = connection_next(c) ) {
72 if ( c->c_writewaiter ) {
75 if ( c->c_currentber != NULL ) {
79 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
80 #ifndef LDAP_LOCALTIME
81 ltm = gmtime( &c->c_starttime );
82 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
84 ltm = localtime( &c->.c_starttime );
85 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
87 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
89 sprintf( buf, "%d : %s : %d : %d : %s : %s%s%s%s", i,
90 buf2, c[i].c_ops_received, c[i].c_ops_completed,
91 c[i].c_cdn ? c[i].c_cdn : "NULLDN",
92 c[i].c_gettingber ? "r" : "",
93 c[i].c_writewaiter ? "w" : "",
94 c[i].c_ops_executing ? "x" : "",
95 c[i].c_ops_pending ? "p" : ""
99 val.bv_len = strlen( buf );
100 attr_merge( e, "connection", vals );
105 sprintf( buf, "%d", nconns );
107 val.bv_len = strlen( buf );
108 attr_merge( e, "currentconnections", vals );
110 sprintf( buf, "%ld", connections_nextid() );
112 val.bv_len = strlen( buf );
113 attr_merge( e, "totalconnections", vals );
115 sprintf( buf, "%d", dtblsize );
117 val.bv_len = strlen( buf );
118 attr_merge( e, "dtablesize", vals );
120 sprintf( buf, "%d", nwritewaiters );
122 val.bv_len = strlen( buf );
123 attr_merge( e, "writewaiters", vals );
125 sprintf( buf, "%d", nreadwaiters );
127 val.bv_len = strlen( buf );
128 attr_merge( e, "readwaiters", vals );
131 sprintf( buf, "%ld", ops_initiated );
133 val.bv_len = strlen( buf );
134 attr_merge( e, "opsinitiated", vals );
136 sprintf( buf, "%ld", ops_completed );
138 val.bv_len = strlen( buf );
139 attr_merge( e, "opscompleted", vals );
141 sprintf( buf, "%ld", num_entries_sent );
143 val.bv_len = strlen( buf );
144 attr_merge( e, "entriessent", vals );
146 sprintf( buf, "%ld", num_bytes_sent );
148 val.bv_len = strlen( buf );
149 attr_merge( e, "bytessent", vals );
152 currenttime = slap_get_time();
154 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
155 #ifndef LDAP_LOCALTIME
156 ltm = gmtime( ¤ttime );
157 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
159 ltm = localtime( ¤ttime );
160 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
163 val.bv_len = strlen( buf );
164 attr_merge( e, "currenttime", vals );
166 #ifndef LDAP_LOCALTIME
167 ltm = gmtime( &starttime );
168 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
170 ltm = localtime( &starttime );
171 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
173 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
176 val.bv_len = strlen( buf );
177 attr_merge( e, "starttime", vals );
179 sprintf( buf, "%d", nbackends );
181 val.bv_len = strlen( buf );
182 attr_merge( e, "nbackends", vals );
184 #ifdef HAVE_THREAD_CONCURRENCY
185 sprintf( buf, "%d", ldap_pvt_thread_get_concurrency() );
187 val.bv_len = strlen( buf );
188 attr_merge( e, "concurrency", vals );
191 send_search_entry( &backends[0], conn, op, e, NULL, 0 );
192 send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
197 #endif /* slapd_monitor_dn */