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 */
51 e->e_dn = 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 sprintf( buf, "%d", active_threads );
63 val.bv_len = strlen( buf );
64 attr_merge( e, "threads", vals );
70 pthread_mutex_lock( &new_conn_mutex );
71 for ( i = 0; i < dtblsize; i++ ) {
72 if ( c[i].c_sb.sb_sd != -1 ) {
74 if ( c[i].c_writewaiter ) {
77 if ( c[i].c_gettingber ) {
80 pthread_mutex_lock( ¤ttime_mutex );
81 #ifndef LDAP_LOCALTIME
82 ltm = gmtime( &c[i].c_starttime );
83 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
85 ltm = localtime( &c[i].c_starttime );
86 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
88 pthread_mutex_unlock( ¤ttime_mutex );
90 pthread_mutex_lock( &c[i].c_dnmutex );
91 sprintf( buf, "%d : %s : %d : %d : %s : %s%s", i,
92 buf2, c[i].c_opsinitiated, c[i].c_opscompleted,
93 c[i].c_dn ? c[i].c_dn : "NULLDN",
94 c[i].c_gettingber ? "r" : "",
95 c[i].c_writewaiter ? "w" : "" );
96 pthread_mutex_unlock( &c[i].c_dnmutex );
98 val.bv_len = strlen( buf );
99 attr_merge( e, "connection", vals );
102 pthread_mutex_unlock( &new_conn_mutex );
104 sprintf( buf, "%d", nconns );
106 val.bv_len = strlen( buf );
107 attr_merge( e, "currentconnections", vals );
109 sprintf( buf, "%d", num_conns );
111 val.bv_len = strlen( buf );
112 attr_merge( e, "totalconnections", vals );
114 sprintf( buf, "%d", dtblsize );
116 val.bv_len = strlen( buf );
117 attr_merge( e, "dtablesize", vals );
119 sprintf( buf, "%d", nwritewaiters );
121 val.bv_len = strlen( buf );
122 attr_merge( e, "writewaiters", vals );
124 sprintf( buf, "%d", nreadwaiters );
126 val.bv_len = strlen( buf );
127 attr_merge( e, "readwaiters", vals );
129 sprintf( buf, "%ld", ops_initiated );
131 val.bv_len = strlen( buf );
132 attr_merge( e, "opsinitiated", vals );
134 sprintf( buf, "%ld", ops_completed );
136 val.bv_len = strlen( buf );
137 attr_merge( e, "opscompleted", vals );
139 sprintf( buf, "%ld", num_entries_sent );
141 val.bv_len = strlen( buf );
142 attr_merge( e, "entriessent", vals );
144 sprintf( buf, "%ld", num_bytes_sent );
146 val.bv_len = strlen( buf );
147 attr_merge( e, "bytessent", vals );
149 pthread_mutex_lock( ¤ttime_mutex );
150 #ifndef LDAP_LOCALTIME
151 ltm = gmtime( ¤ttime );
152 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
154 ltm = localtime( ¤ttime );
155 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
157 pthread_mutex_unlock( ¤ttime_mutex );
159 val.bv_len = strlen( buf );
160 attr_merge( e, "currenttime", vals );
162 pthread_mutex_lock( ¤ttime_mutex );
163 #ifndef LDAP_LOCALTIME
164 ltm = gmtime( &starttime );
165 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
167 ltm = localtime( &starttime );
168 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
170 pthread_mutex_unlock( ¤ttime_mutex );
172 val.bv_len = strlen( buf );
173 attr_merge( e, "starttime", vals );
175 sprintf( buf, "%d", nbackends );
177 val.bv_len = strlen( buf );
178 attr_merge( e, "nbackends", vals );
181 sprintf( buf, "%d", thr_getconcurrency() );
183 val.bv_len = strlen( buf );
184 attr_merge( e, "concurrency", vals );
187 send_search_entry( &backends[0], conn, op, e, NULL, 0 );
188 send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
193 #endif /* slapd_monitor_dn */