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().
23 #include <sys/types.h>
24 #include <sys/socket.h>
26 #include "ldapconfig.h"
28 #if defined( SLAPD_MONITOR_DN )
31 extern Backend *backends;
32 extern int active_threads;
35 extern long ops_initiated;
36 extern long ops_completed;
37 extern long num_entries_sent;
38 extern long num_bytes_sent;
39 extern time_t currenttime;
40 extern time_t starttime;
43 extern pthread_mutex_t new_conn_mutex;
44 extern pthread_mutex_t currenttime_mutex;
46 extern char Versionstr[];
49 monitor_info( Connection *conn, Operation *op )
52 char buf[BUFSIZ], buf2[22];
54 struct berval *vals[2];
55 int i, nconns, nwritewaiters, nreadwaiters;
62 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
63 /* initialize reader/writer lock */
66 e->e_dn = strdup( SLAPD_MONITOR_DN );
68 val.bv_val = Versionstr;
69 if (( p = strchr( Versionstr, '\n' )) == NULL ) {
70 val.bv_len = strlen( Versionstr );
72 val.bv_len = p - Versionstr;
74 attr_merge( e, "version", vals );
76 sprintf( buf, "%d", active_threads );
78 val.bv_len = strlen( buf );
79 attr_merge( e, "threads", vals );
85 pthread_mutex_lock( &new_conn_mutex );
86 for ( i = 0; i < dtblsize; i++ ) {
87 if ( c[i].c_sb.sb_sd != -1 ) {
89 if ( c[i].c_writewaiter ) {
92 if ( c[i].c_gettingber ) {
95 pthread_mutex_lock( ¤ttime_mutex );
96 ltm = localtime( &c[i].c_starttime );
98 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
100 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
102 pthread_mutex_unlock( ¤ttime_mutex );
104 pthread_mutex_lock( &c[i].c_dnmutex );
105 sprintf( buf, "%d : %s : %ld : %ld : %s : %s%s", i,
106 buf2, c[i].c_opsinitiated, c[i].c_opscompleted,
107 c[i].c_dn ? c[i].c_dn : "NULLDN",
108 c[i].c_gettingber ? "r" : "",
109 c[i].c_writewaiter ? "w" : "" );
110 pthread_mutex_unlock( &c[i].c_dnmutex );
112 val.bv_len = strlen( buf );
113 attr_merge( e, "connection", vals );
116 pthread_mutex_unlock( &new_conn_mutex );
118 sprintf( buf, "%d", nconns );
120 val.bv_len = strlen( buf );
121 attr_merge( e, "currentconnections", vals );
123 sprintf( buf, "%d", num_conns );
125 val.bv_len = strlen( buf );
126 attr_merge( e, "totalconnections", vals );
128 sprintf( buf, "%d", dtblsize );
130 val.bv_len = strlen( buf );
131 attr_merge( e, "dtablesize", vals );
133 sprintf( buf, "%d", nwritewaiters );
135 val.bv_len = strlen( buf );
136 attr_merge( e, "writewaiters", vals );
138 sprintf( buf, "%d", nreadwaiters );
140 val.bv_len = strlen( buf );
141 attr_merge( e, "readwaiters", vals );
143 sprintf( buf, "%ld", ops_initiated );
145 val.bv_len = strlen( buf );
146 attr_merge( e, "opsinitiated", vals );
148 sprintf( buf, "%ld", ops_completed );
150 val.bv_len = strlen( buf );
151 attr_merge( e, "opscompleted", vals );
153 sprintf( buf, "%ld", num_entries_sent );
155 val.bv_len = strlen( buf );
156 attr_merge( e, "entriessent", vals );
158 sprintf( buf, "%ld", num_bytes_sent );
160 val.bv_len = strlen( buf );
161 attr_merge( e, "bytessent", vals );
163 pthread_mutex_lock( ¤ttime_mutex );
164 ltm = localtime( ¤ttime );
166 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
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, "currenttime", vals );
175 pthread_mutex_lock( ¤ttime_mutex );
176 ltm = localtime( &starttime );
178 strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
180 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
182 pthread_mutex_unlock( ¤ttime_mutex );
184 val.bv_len = strlen( buf );
185 attr_merge( e, "starttime", vals );
187 sprintf( buf, "%d", nbackends );
189 val.bv_len = strlen( buf );
190 attr_merge( e, "nbackends", vals );
192 #ifdef THREAD_SUNOS5_LWP
193 sprintf( buf, "%d", thr_getconcurrency() );
195 val.bv_len = strlen( buf );
196 attr_merge( e, "concurrency", vals );
199 send_search_entry( &backends[0], conn, op, e, NULL, 0 );
200 send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
205 #endif /* slapd_monitor_dn */