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 #include <sys/types.h>
16 #include <sys/socket.h>
18 #include "ldapconfig.h"
20 #if defined( SLAPD_MONITOR_DN )
23 extern Backend *backends;
24 extern int active_threads;
27 extern long ops_initiated;
28 extern long ops_completed;
29 extern long num_entries_sent;
30 extern long num_bytes_sent;
31 extern time_t currenttime;
32 extern time_t starttime;
36 extern char Versionstr[];
39 * no mutex protection in here - take our chances!
43 monitor_info( Connection *conn, Operation *op )
46 char buf[BUFSIZ], buf2[20];
48 struct berval *vals[2];
49 int i, nconns, nwritewaiters, nreadwaiters;
56 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
58 e->e_dn = strdup( SLAPD_MONITOR_DN );
60 val.bv_val = Versionstr;
61 if (( p = strchr( Versionstr, '\n' )) == NULL ) {
62 val.bv_len = strlen( Versionstr );
64 val.bv_len = p - Versionstr;
66 attr_merge( e, "version", vals );
68 sprintf( buf, "%d", active_threads );
70 val.bv_len = strlen( buf );
71 attr_merge( e, "threads", vals );
76 for ( i = 0; i < dtblsize; i++ ) {
77 if ( c[i].c_sb.sb_sd != -1 ) {
79 if ( c[i].c_writewaiter ) {
82 if ( c[i].c_gettingber ) {
85 ltm = localtime( &c[i].c_starttime );
86 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
87 pthread_mutex_lock( &c[i].c_dnmutex );
88 sprintf( buf, "%d : %s : %ld : %ld : %s : %s%s", i,
89 buf2, c[i].c_opsinitiated, c[i].c_opscompleted,
90 c[i].c_dn ? c[i].c_dn : "NULLDN",
91 c[i].c_gettingber ? "r" : "",
92 c[i].c_writewaiter ? "w" : "" );
93 pthread_mutex_unlock( &c[i].c_dnmutex );
95 val.bv_len = strlen( buf );
96 attr_merge( e, "connection", vals );
99 sprintf( buf, "%d", nconns );
101 val.bv_len = strlen( buf );
102 attr_merge( e, "currentconnections", vals );
104 sprintf( buf, "%d", num_conns );
106 val.bv_len = strlen( buf );
107 attr_merge( e, "totalconnections", vals );
109 sprintf( buf, "%d", dtblsize );
111 val.bv_len = strlen( buf );
112 attr_merge( e, "dtablesize", vals );
114 sprintf( buf, "%d", nwritewaiters );
116 val.bv_len = strlen( buf );
117 attr_merge( e, "writewaiters", vals );
119 sprintf( buf, "%d", nreadwaiters );
121 val.bv_len = strlen( buf );
122 attr_merge( e, "readwaiters", vals );
124 sprintf( buf, "%ld", ops_initiated );
126 val.bv_len = strlen( buf );
127 attr_merge( e, "opsinitiated", vals );
129 sprintf( buf, "%ld", ops_completed );
131 val.bv_len = strlen( buf );
132 attr_merge( e, "opscompleted", vals );
134 sprintf( buf, "%ld", num_entries_sent );
136 val.bv_len = strlen( buf );
137 attr_merge( e, "entriessent", vals );
139 sprintf( buf, "%ld", num_bytes_sent );
141 val.bv_len = strlen( buf );
142 attr_merge( e, "bytessent", vals );
144 ltm = localtime( ¤ttime );
145 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
147 val.bv_len = strlen( buf );
148 attr_merge( e, "currenttime", vals );
150 ltm = localtime( &starttime );
151 strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
153 val.bv_len = strlen( buf );
154 attr_merge( e, "starttime", vals );
156 sprintf( buf, "%d", nbackends );
158 val.bv_len = strlen( buf );
159 attr_merge( e, "nbackends", vals );
161 #ifdef THREAD_SUNOS5_LWP
162 sprintf( buf, "%d", thr_getconcurrency() );
164 val.bv_len = strlen( buf );
165 attr_merge( e, "concurrency", vals );
168 send_search_entry( &backends[0], conn, op, e, NULL, 0 );
169 send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
174 #endif /* slapd_monitor_dn */