]> git.sur5r.net Git - openldap/blob - servers/slapd/monitor.c
Add Kerberos V5 support from Predrag Balorda <pele@artewisdom.com>
[openldap] / servers / slapd / monitor.c
1 /*
2  * Copyright (c) 1995 Regents of the University of Michigan.
3  * All rights reserved.
4  *
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.
11  */
12
13 /* Revision history
14  *
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().
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <time.h>
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include "slap.h"
26 #include "ldapconfig.h"
27
28 #if defined( SLAPD_MONITOR_DN )
29
30 extern int              nbackends;
31 extern Backend          *backends;
32 extern int              active_threads;
33 extern int              dtblsize;
34 extern Connection       *c;
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;
41 extern int              num_conns;
42
43 extern pthread_mutex_t  new_conn_mutex;
44 extern pthread_mutex_t  currenttime_mutex;
45
46 extern char Versionstr[];
47
48 void
49 monitor_info( Connection *conn, Operation *op )
50 {
51         Entry           *e;
52         char            buf[BUFSIZ], buf2[20];
53         struct berval   val;
54         struct berval   *vals[2];
55         int             i, nconns, nwritewaiters, nreadwaiters;
56         struct tm       *ltm;
57         char            *p, *tmpdn;
58
59         vals[0] = &val;
60         vals[1] = NULL;
61
62         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
63         e->e_attrs = NULL;
64         e->e_dn = strdup( SLAPD_MONITOR_DN );
65
66         val.bv_val = Versionstr;
67         if (( p = strchr( Versionstr, '\n' )) == NULL ) {
68                 val.bv_len = strlen( Versionstr );
69         } else {
70                 val.bv_len = p - Versionstr;
71         }
72         attr_merge( e, "version", vals );
73
74         sprintf( buf, "%d", active_threads );
75         val.bv_val = buf;
76         val.bv_len = strlen( buf );
77         attr_merge( e, "threads", vals );
78
79         nconns = 0;
80         nwritewaiters = 0;
81         nreadwaiters = 0;
82
83         pthread_mutex_lock( &new_conn_mutex );
84         for ( i = 0; i < dtblsize; i++ ) {
85                 if ( c[i].c_sb.sb_sd != -1 ) {
86                         nconns++;
87                         if ( c[i].c_writewaiter ) {
88                                 nwritewaiters++;
89                         }
90                         if ( c[i].c_gettingber ) {
91                                 nreadwaiters++;
92                         }
93                         pthread_mutex_lock( &currenttime_mutex );
94                         ltm = localtime( &c[i].c_starttime );
95                         strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
96                         pthread_mutex_unlock( &currenttime_mutex );
97
98                         pthread_mutex_lock( &c[i].c_dnmutex );
99                         sprintf( buf, "%d : %s : %ld : %ld : %s : %s%s", i,
100                             buf2, c[i].c_opsinitiated, c[i].c_opscompleted,
101                             c[i].c_dn ? c[i].c_dn : "NULLDN",
102                             c[i].c_gettingber ? "r" : "",
103                             c[i].c_writewaiter ? "w" : "" );
104                         pthread_mutex_unlock( &c[i].c_dnmutex );
105                         val.bv_val = buf;
106                         val.bv_len = strlen( buf );
107                         attr_merge( e, "connection", vals );
108                 }
109         }
110         pthread_mutex_unlock( &new_conn_mutex );
111
112         sprintf( buf, "%d", nconns );
113         val.bv_val = buf;
114         val.bv_len = strlen( buf );
115         attr_merge( e, "currentconnections", vals );
116
117         sprintf( buf, "%d", num_conns );
118         val.bv_val = buf;
119         val.bv_len = strlen( buf );
120         attr_merge( e, "totalconnections", vals );
121
122         sprintf( buf, "%d", dtblsize );
123         val.bv_val = buf;
124         val.bv_len = strlen( buf );
125         attr_merge( e, "dtablesize", vals );
126
127         sprintf( buf, "%d", nwritewaiters );
128         val.bv_val = buf;
129         val.bv_len = strlen( buf );
130         attr_merge( e, "writewaiters", vals );
131
132         sprintf( buf, "%d", nreadwaiters );
133         val.bv_val = buf;
134         val.bv_len = strlen( buf );
135         attr_merge( e, "readwaiters", vals );
136
137         sprintf( buf, "%ld", ops_initiated );
138         val.bv_val = buf;
139         val.bv_len = strlen( buf );
140         attr_merge( e, "opsinitiated", vals );
141
142         sprintf( buf, "%ld", ops_completed );
143         val.bv_val = buf;
144         val.bv_len = strlen( buf );
145         attr_merge( e, "opscompleted", vals );
146
147         sprintf( buf, "%ld", num_entries_sent );
148         val.bv_val = buf;
149         val.bv_len = strlen( buf );
150         attr_merge( e, "entriessent", vals );
151
152         sprintf( buf, "%ld", num_bytes_sent );
153         val.bv_val = buf;
154         val.bv_len = strlen( buf );
155         attr_merge( e, "bytessent", vals );
156
157         pthread_mutex_lock( &currenttime_mutex );
158         ltm = localtime( &currenttime );
159         strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
160         pthread_mutex_unlock( &currenttime_mutex );
161         val.bv_val = buf;
162         val.bv_len = strlen( buf );
163         attr_merge( e, "currenttime", vals );
164
165         pthread_mutex_lock( &currenttime_mutex );
166         ltm = localtime( &starttime );
167         strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
168         pthread_mutex_unlock( &currenttime_mutex );
169         val.bv_val = buf;
170         val.bv_len = strlen( buf );
171         attr_merge( e, "starttime", vals );
172
173         sprintf( buf, "%d", nbackends );
174         val.bv_val = buf;
175         val.bv_len = strlen( buf );
176         attr_merge( e, "nbackends", vals );
177
178 #ifdef THREAD_SUNOS5_LWP
179         sprintf( buf, "%d", thr_getconcurrency() );
180         val.bv_val = buf;
181         val.bv_len = strlen( buf );
182         attr_merge( e, "concurrency", vals );
183 #endif
184
185         send_search_entry( &backends[0], conn, op, e, NULL, 0 );
186         send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
187
188         entry_free( e );
189 }
190
191 #endif /* slapd_monitor_dn */