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>
29 #include "ldapconfig.h"
31 #if defined( SLAPD_MONITOR_DN )
34 extern Backend *backends;
35 extern int active_threads;
38 extern long ops_initiated;
39 extern long ops_completed;
40 extern long num_entries_sent;
41 extern long num_bytes_sent;
42 extern time_t currenttime;
43 extern time_t starttime;
46 extern pthread_mutex_t new_conn_mutex;
47 extern pthread_mutex_t currenttime_mutex;
49 extern char Versionstr[];
52 monitor_info( Connection *conn, Operation *op )
55 char buf[BUFSIZ], buf2[22];
57 struct berval *vals[2];
58 int i, nconns, nwritewaiters, nreadwaiters;
65 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
66 /* initialize reader/writer lock */
69 e->e_dn = strdup( SLAPD_MONITOR_DN );
71 val.bv_val = Versionstr;
72 if (( p = strchr( Versionstr, '\n' )) == NULL ) {
73 val.bv_len = strlen( Versionstr );
75 val.bv_len = p - Versionstr;
77 attr_merge( e, "version", vals );
79 sprintf( buf, "%d", active_threads );
81 val.bv_len = strlen( buf );
82 attr_merge( e, "threads", vals );
88 pthread_mutex_lock( &new_conn_mutex );
89 for ( i = 0; i < dtblsize; i++ ) {
90 if ( c[i].c_sb.sb_sd != -1 ) {
92 if ( c[i].c_writewaiter ) {
95 if ( c[i].c_gettingber ) {
98 pthread_mutex_lock( ¤ttime_mutex );
99 #ifndef LDAP_LOCALTIME
100 ltm = gmtime( &c[i].c_starttime );
101 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
103 ltm = localtime( &c[i].c_starttime );
104 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
106 pthread_mutex_unlock( ¤ttime_mutex );
108 pthread_mutex_lock( &c[i].c_dnmutex );
109 sprintf( buf, "%d : %s : %ld : %ld : %s : %s%s", i,
110 buf2, c[i].c_opsinitiated, c[i].c_opscompleted,
111 c[i].c_dn ? c[i].c_dn : "NULLDN",
112 c[i].c_gettingber ? "r" : "",
113 c[i].c_writewaiter ? "w" : "" );
114 pthread_mutex_unlock( &c[i].c_dnmutex );
116 val.bv_len = strlen( buf );
117 attr_merge( e, "connection", vals );
120 pthread_mutex_unlock( &new_conn_mutex );
122 sprintf( buf, "%d", nconns );
124 val.bv_len = strlen( buf );
125 attr_merge( e, "currentconnections", vals );
127 sprintf( buf, "%d", num_conns );
129 val.bv_len = strlen( buf );
130 attr_merge( e, "totalconnections", vals );
132 sprintf( buf, "%d", dtblsize );
134 val.bv_len = strlen( buf );
135 attr_merge( e, "dtablesize", vals );
137 sprintf( buf, "%d", nwritewaiters );
139 val.bv_len = strlen( buf );
140 attr_merge( e, "writewaiters", vals );
142 sprintf( buf, "%d", nreadwaiters );
144 val.bv_len = strlen( buf );
145 attr_merge( e, "readwaiters", vals );
147 sprintf( buf, "%ld", ops_initiated );
149 val.bv_len = strlen( buf );
150 attr_merge( e, "opsinitiated", vals );
152 sprintf( buf, "%ld", ops_completed );
154 val.bv_len = strlen( buf );
155 attr_merge( e, "opscompleted", vals );
157 sprintf( buf, "%ld", num_entries_sent );
159 val.bv_len = strlen( buf );
160 attr_merge( e, "entriessent", vals );
162 sprintf( buf, "%ld", num_bytes_sent );
164 val.bv_len = strlen( buf );
165 attr_merge( e, "bytessent", vals );
167 pthread_mutex_lock( ¤ttime_mutex );
168 #ifndef LDAP_LOCALTIME
169 ltm = gmtime( ¤ttime );
170 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
172 ltm = localtime( ¤ttime );
173 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
175 pthread_mutex_unlock( ¤ttime_mutex );
177 val.bv_len = strlen( buf );
178 attr_merge( e, "currenttime", vals );
180 pthread_mutex_lock( ¤ttime_mutex );
181 #ifndef LDAP_LOCALTIME
182 ltm = gmtime( &starttime );
183 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
185 ltm = localtime( &starttime );
186 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
188 pthread_mutex_unlock( ¤ttime_mutex );
190 val.bv_len = strlen( buf );
191 attr_merge( e, "starttime", vals );
193 sprintf( buf, "%d", nbackends );
195 val.bv_len = strlen( buf );
196 attr_merge( e, "nbackends", vals );
199 sprintf( buf, "%d", thr_getconcurrency() );
201 val.bv_len = strlen( buf );
202 attr_merge( e, "concurrency", vals );
205 send_search_entry( &backends[0], conn, op, e, NULL, 0 );
206 send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
211 #endif /* slapd_monitor_dn */