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.
15 * 5-Jun-96 jeff.hodges@stanford.edu
16 * Added locking of new_conn_mutex when traversing the c[] array.
17 * Added locking of currenttime_mutex to protect call(s) to localtime().
24 #include <ac/socket.h>
25 #include <ac/string.h>
28 #include "ldapconfig.h"
31 #if defined( SLAPD_MONITOR_DN )
34 monitor_info( Connection *conn, Operation *op )
37 char buf[BUFSIZ], buf2[22];
39 struct berval *vals[2];
40 int i, nconns, nwritewaiters, nreadwaiters;
47 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
48 /* initialize reader/writer lock */
50 e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
51 e->e_ndn = dn_normalize_case( ch_strdup(SLAPD_MONITOR_DN) );
54 val.bv_val = Versionstr;
55 if (( p = strchr( Versionstr, '\n' )) == NULL ) {
56 val.bv_len = strlen( Versionstr );
58 val.bv_len = p - Versionstr;
60 attr_merge( e, "version", vals );
62 sprintf( buf, "%d", active_threads );
64 val.bv_len = strlen( buf );
65 attr_merge( e, "threads", vals );
71 ldap_pvt_thread_mutex_lock( &new_conn_mutex );
72 for ( i = 0; i < dtblsize; i++ ) {
73 if ( lber_pvt_sb_in_use(&(c[i].c_sb)) ) {
75 if ( c[i].c_writewaiter ) {
78 if ( c[i].c_gettingber ) {
81 ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
82 #ifndef LDAP_LOCALTIME
83 ltm = gmtime( &c[i].c_starttime );
84 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
86 ltm = localtime( &c[i].c_starttime );
87 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
89 ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );
91 ldap_pvt_thread_mutex_lock( &c[i].c_dnmutex );
92 sprintf( buf, "%d : %s : %d : %d : %s : %s%s%s%s", i,
93 buf2, c[i].c_ops_received, c[i].c_ops_completed,
94 c[i].c_cdn ? c[i].c_cdn : "NULLDN",
95 c[i].c_gettingber ? "r" : "",
96 c[i].c_writewaiter ? "w" : "",
97 c[i].c_ops_executing ? "x" : "",
98 c[i].c_ops_pending ? "p" : ""
100 ldap_pvt_thread_mutex_unlock( &c[i].c_dnmutex );
102 val.bv_len = strlen( buf );
103 attr_merge( e, "connection", vals );
106 ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
108 sprintf( buf, "%d", nconns );
110 val.bv_len = strlen( buf );
111 attr_merge( e, "currentconnections", vals );
113 sprintf( buf, "%d", num_conns );
115 val.bv_len = strlen( buf );
116 attr_merge( e, "totalconnections", vals );
118 sprintf( buf, "%d", dtblsize );
120 val.bv_len = strlen( buf );
121 attr_merge( e, "dtablesize", vals );
123 sprintf( buf, "%d", nwritewaiters );
125 val.bv_len = strlen( buf );
126 attr_merge( e, "writewaiters", vals );
128 sprintf( buf, "%d", nreadwaiters );
130 val.bv_len = strlen( buf );
131 attr_merge( e, "readwaiters", vals );
133 sprintf( buf, "%ld", ops_initiated );
135 val.bv_len = strlen( buf );
136 attr_merge( e, "opsinitiated", vals );
138 sprintf( buf, "%ld", ops_completed );
140 val.bv_len = strlen( buf );
141 attr_merge( e, "opscompleted", vals );
143 sprintf( buf, "%ld", num_entries_sent );
145 val.bv_len = strlen( buf );
146 attr_merge( e, "entriessent", vals );
148 sprintf( buf, "%ld", num_bytes_sent );
150 val.bv_len = strlen( buf );
151 attr_merge( e, "bytessent", vals );
153 ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
154 #ifndef LDAP_LOCALTIME
155 ltm = gmtime( ¤ttime );
156 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
158 ltm = localtime( ¤ttime );
159 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
161 ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );
163 val.bv_len = strlen( buf );
164 attr_merge( e, "currenttime", vals );
166 ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
167 #ifndef LDAP_LOCALTIME
168 ltm = gmtime( &starttime );
169 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
171 ltm = localtime( &starttime );
172 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
174 ldap_pvt_thread_mutex_unlock( ¤ttime_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 */