]> git.sur5r.net Git - openldap/blob - servers/slapd/monitor.c
import localtime -> gmtime change from -devel
[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 "portable.h"
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <time.h>
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include "slap.h"
28 #include "ldapconfig.h"
29
30 #if defined( SLAPD_MONITOR_DN )
31
32 extern int              nbackends;
33 extern Backend          *backends;
34 extern int              active_threads;
35 extern int              dtblsize;
36 extern Connection       *c;
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;
43 extern int              num_conns;
44
45 extern pthread_mutex_t  new_conn_mutex;
46 extern pthread_mutex_t  currenttime_mutex;
47
48 extern char Versionstr[];
49
50 void
51 monitor_info( Connection *conn, Operation *op )
52 {
53         Entry           *e;
54         char            buf[BUFSIZ], buf2[22];
55         struct berval   val;
56         struct berval   *vals[2];
57         int             i, nconns, nwritewaiters, nreadwaiters;
58         struct tm       *ltm;
59         char            *p, *tmpdn;
60
61         vals[0] = &val;
62         vals[1] = NULL;
63
64         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
65         /* initialize reader/writer lock */
66         entry_rdwr_init(e);
67         e->e_attrs = NULL;
68         e->e_dn = strdup( SLAPD_MONITOR_DN );
69
70         val.bv_val = Versionstr;
71         if (( p = strchr( Versionstr, '\n' )) == NULL ) {
72                 val.bv_len = strlen( Versionstr );
73         } else {
74                 val.bv_len = p - Versionstr;
75         }
76         attr_merge( e, "version", vals );
77
78         sprintf( buf, "%d", active_threads );
79         val.bv_val = buf;
80         val.bv_len = strlen( buf );
81         attr_merge( e, "threads", vals );
82
83         nconns = 0;
84         nwritewaiters = 0;
85         nreadwaiters = 0;
86
87         pthread_mutex_lock( &new_conn_mutex );
88         for ( i = 0; i < dtblsize; i++ ) {
89                 if ( c[i].c_sb.sb_sd != -1 ) {
90                         nconns++;
91                         if ( c[i].c_writewaiter ) {
92                                 nwritewaiters++;
93                         }
94                         if ( c[i].c_gettingber ) {
95                                 nreadwaiters++;
96                         }
97                         pthread_mutex_lock( &currenttime_mutex );
98 #ifndef LDAP_LOCALTIME
99                         ltm = gmtime( &c[i].c_starttime );
100                         strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
101 #else
102                         ltm = localtime( &c[i].c_starttime );
103                         strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
104 #endif
105                         pthread_mutex_unlock( &currenttime_mutex );
106
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 );
114                         val.bv_val = buf;
115                         val.bv_len = strlen( buf );
116                         attr_merge( e, "connection", vals );
117                 }
118         }
119         pthread_mutex_unlock( &new_conn_mutex );
120
121         sprintf( buf, "%d", nconns );
122         val.bv_val = buf;
123         val.bv_len = strlen( buf );
124         attr_merge( e, "currentconnections", vals );
125
126         sprintf( buf, "%d", num_conns );
127         val.bv_val = buf;
128         val.bv_len = strlen( buf );
129         attr_merge( e, "totalconnections", vals );
130
131         sprintf( buf, "%d", dtblsize );
132         val.bv_val = buf;
133         val.bv_len = strlen( buf );
134         attr_merge( e, "dtablesize", vals );
135
136         sprintf( buf, "%d", nwritewaiters );
137         val.bv_val = buf;
138         val.bv_len = strlen( buf );
139         attr_merge( e, "writewaiters", vals );
140
141         sprintf( buf, "%d", nreadwaiters );
142         val.bv_val = buf;
143         val.bv_len = strlen( buf );
144         attr_merge( e, "readwaiters", vals );
145
146         sprintf( buf, "%ld", ops_initiated );
147         val.bv_val = buf;
148         val.bv_len = strlen( buf );
149         attr_merge( e, "opsinitiated", vals );
150
151         sprintf( buf, "%ld", ops_completed );
152         val.bv_val = buf;
153         val.bv_len = strlen( buf );
154         attr_merge( e, "opscompleted", vals );
155
156         sprintf( buf, "%ld", num_entries_sent );
157         val.bv_val = buf;
158         val.bv_len = strlen( buf );
159         attr_merge( e, "entriessent", vals );
160
161         sprintf( buf, "%ld", num_bytes_sent );
162         val.bv_val = buf;
163         val.bv_len = strlen( buf );
164         attr_merge( e, "bytessent", vals );
165
166         pthread_mutex_lock( &currenttime_mutex );
167 #ifndef LDAP_LOCALTIME
168         ltm = gmtime( &currenttime );
169         strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
170 #else
171         ltm = localtime( &currenttime );
172         strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
173 #endif
174         pthread_mutex_unlock( &currenttime_mutex );
175         val.bv_val = buf;
176         val.bv_len = strlen( buf );
177         attr_merge( e, "currenttime", vals );
178
179         pthread_mutex_lock( &currenttime_mutex );
180 #ifndef LDAP_LOCALTIME
181         ltm = gmtime( &starttime );
182         strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
183 #else
184         ltm = localtime( &starttime );
185         strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
186 #endif
187         pthread_mutex_unlock( &currenttime_mutex );
188         val.bv_val = buf;
189         val.bv_len = strlen( buf );
190         attr_merge( e, "starttime", vals );
191
192         sprintf( buf, "%d", nbackends );
193         val.bv_val = buf;
194         val.bv_len = strlen( buf );
195         attr_merge( e, "nbackends", vals );
196
197 #ifdef THREAD_SUNOS5_LWP
198         sprintf( buf, "%d", thr_getconcurrency() );
199         val.bv_val = buf;
200         val.bv_len = strlen( buf );
201         attr_merge( e, "concurrency", vals );
202 #endif
203
204         send_search_entry( &backends[0], conn, op, e, NULL, 0 );
205         send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
206
207         entry_free( e );
208 }
209
210 #endif /* slapd_monitor_dn */