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().
25 #include <sys/types.h>
26 #include <sys/socket.h>
28 #include "ldapconfig.h"
30 #if defined( SLAPD_MONITOR_DN )
33 extern Backend *backends;
34 extern int active_threads;
37 extern long ops_initiated;
38 extern long ops_completed;
39 extern long num_entries_sent;
40 extern long num_bytes_sent;
41 extern time_t currenttime;
42 extern time_t starttime;
45 extern pthread_mutex_t new_conn_mutex;
46 extern pthread_mutex_t currenttime_mutex;
48 extern char Versionstr[];
51 monitor_info( Connection *conn, Operation *op )
54 char buf[BUFSIZ], buf2[22];
56 struct berval *vals[2];
57 int i, nconns, nwritewaiters, nreadwaiters;
64 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
65 /* initialize reader/writer lock */
68 e->e_dn = strdup( SLAPD_MONITOR_DN );
70 val.bv_val = Versionstr;
71 if (( p = strchr( Versionstr, '\n' )) == NULL ) {
72 val.bv_len = strlen( Versionstr );
74 val.bv_len = p - Versionstr;
76 attr_merge( e, "version", vals );
78 sprintf( buf, "%d", active_threads );
80 val.bv_len = strlen( buf );
81 attr_merge( e, "threads", vals );
87 pthread_mutex_lock( &new_conn_mutex );
88 for ( i = 0; i < dtblsize; i++ ) {
89 if ( c[i].c_sb.sb_sd != -1 ) {
91 if ( c[i].c_writewaiter ) {
94 if ( c[i].c_gettingber ) {
97 pthread_mutex_lock( ¤ttime_mutex );
98 #ifndef LDAP_LOCALTIME
99 ltm = gmtime( &c[i].c_starttime );
100 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
102 ltm = localtime( &c[i].c_starttime );
103 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
105 pthread_mutex_unlock( ¤ttime_mutex );
107 pthread_mutex_lock( &c[i].c_dnmutex );
108 sprintf( buf, "%d : %s : %ld : %ld : %s : %s%s", i,
109 buf2, c[i].c_opsinitiated, c[i].c_opscompleted,
110 c[i].c_dn ? c[i].c_dn : "NULLDN",
111 c[i].c_gettingber ? "r" : "",
112 c[i].c_writewaiter ? "w" : "" );
113 pthread_mutex_unlock( &c[i].c_dnmutex );
115 val.bv_len = strlen( buf );
116 attr_merge( e, "connection", vals );
119 pthread_mutex_unlock( &new_conn_mutex );
121 sprintf( buf, "%d", nconns );
123 val.bv_len = strlen( buf );
124 attr_merge( e, "currentconnections", vals );
126 sprintf( buf, "%d", num_conns );
128 val.bv_len = strlen( buf );
129 attr_merge( e, "totalconnections", vals );
131 sprintf( buf, "%d", dtblsize );
133 val.bv_len = strlen( buf );
134 attr_merge( e, "dtablesize", vals );
136 sprintf( buf, "%d", nwritewaiters );
138 val.bv_len = strlen( buf );
139 attr_merge( e, "writewaiters", vals );
141 sprintf( buf, "%d", nreadwaiters );
143 val.bv_len = strlen( buf );
144 attr_merge( e, "readwaiters", vals );
146 sprintf( buf, "%ld", ops_initiated );
148 val.bv_len = strlen( buf );
149 attr_merge( e, "opsinitiated", vals );
151 sprintf( buf, "%ld", ops_completed );
153 val.bv_len = strlen( buf );
154 attr_merge( e, "opscompleted", vals );
156 sprintf( buf, "%ld", num_entries_sent );
158 val.bv_len = strlen( buf );
159 attr_merge( e, "entriessent", vals );
161 sprintf( buf, "%ld", num_bytes_sent );
163 val.bv_len = strlen( buf );
164 attr_merge( e, "bytessent", vals );
166 pthread_mutex_lock( ¤ttime_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 );
174 pthread_mutex_unlock( ¤ttime_mutex );
176 val.bv_len = strlen( buf );
177 attr_merge( e, "currenttime", vals );
179 pthread_mutex_lock( ¤ttime_mutex );
180 #ifndef LDAP_LOCALTIME
181 ltm = gmtime( &starttime );
182 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
184 ltm = localtime( &starttime );
185 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
187 pthread_mutex_unlock( ¤ttime_mutex );
189 val.bv_len = strlen( buf );
190 attr_merge( e, "starttime", vals );
192 sprintf( buf, "%d", nbackends );
194 val.bv_len = strlen( buf );
195 attr_merge( e, "nbackends", vals );
197 #ifdef THREAD_SUNOS5_LWP
198 sprintf( buf, "%d", thr_getconcurrency() );
200 val.bv_len = strlen( buf );
201 attr_merge( e, "concurrency", vals );
204 send_search_entry( &backends[0], conn, op, e, NULL, 0 );
205 send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
210 #endif /* slapd_monitor_dn */