]> git.sur5r.net Git - openldap/blob - servers/slapd/monitor.c
slap_set_time() is no longer necessary.
[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 #include "portable.h"
14
15 #include <stdio.h>
16
17 #include <ac/socket.h>
18 #include <ac/string.h>
19 #include <ac/time.h>
20
21 #include "ldapconfig.h"
22 #include "slap.h"
23
24 #if defined( SLAPD_MONITOR_DN )
25
26 void
27 monitor_info( Connection *conn, Operation *op )
28 {
29         Entry           *e;
30         char            buf[BUFSIZ], buf2[22];
31         struct berval   val;
32         struct berval   *vals[2];
33         int             i, nconns, nwritewaiters, nreadwaiters;
34         struct tm       *ltm;
35         char            *p;
36         Connection *c;
37         time_t          currenttime;
38
39         vals[0] = &val;
40         vals[1] = NULL;
41
42         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
43         /* initialize reader/writer lock */
44         e->e_attrs = NULL;
45         e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
46         e->e_ndn = dn_normalize_case( ch_strdup(SLAPD_MONITOR_DN) );
47         e->e_private = NULL;
48
49         val.bv_val = Versionstr;
50         if (( p = strchr( Versionstr, '\n' )) == NULL ) {
51                 val.bv_len = strlen( Versionstr );
52         } else {
53                 val.bv_len = p - Versionstr;
54         }
55         attr_merge( e, "version", vals );
56
57         ldap_pvt_thread_mutex_lock( &active_threads_mutex );
58         sprintf( buf, "%d", active_threads );
59         ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
60         val.bv_val = buf;
61         val.bv_len = strlen( buf );
62         attr_merge( e, "threads", vals );
63
64         nconns = 0;
65         nwritewaiters = 0;
66         nreadwaiters = 0;
67
68 #ifdef LDAP_COUNTERS
69         /* loop through the connections */
70         for ( c = connection_first() ; c != NULL;  c = connection_next(c) ) {
71                 nconns++;
72                 if ( c->c_writewaiter ) {
73                         nwritewaiters++;
74                 }
75                 if ( c->c_currentber != NULL ) {
76                         nreadwaiters++;
77                 }
78
79                 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
80 #ifndef LDAP_LOCALTIME
81                 ltm = gmtime( &c->c_starttime );
82                 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
83 #else
84                 ltm = localtime( &c->.c_starttime );
85                 strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
86 #endif
87                 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
88
89                 sprintf( buf, "%d : %s : %d : %d : %s : %s%s%s%s", i,
90                     buf2, c[i].c_ops_received, c[i].c_ops_completed,
91                     c[i].c_cdn ? c[i].c_cdn : "NULLDN",
92                     c[i].c_gettingber ? "r" : "",
93                     c[i].c_writewaiter ? "w" : "",
94                     c[i].c_ops_executing ? "x" : "",
95                     c[i].c_ops_pending ? "p" : ""
96                 );
97
98                 val.bv_val = buf;
99                 val.bv_len = strlen( buf );
100                 attr_merge( e, "connection", vals );
101         }
102         connection_done(c);
103 #endif
104
105         sprintf( buf, "%d", nconns );
106         val.bv_val = buf;
107         val.bv_len = strlen( buf );
108         attr_merge( e, "currentconnections", vals );
109
110         sprintf( buf, "%ld", connections_nextid() );
111         val.bv_val = buf;
112         val.bv_len = strlen( buf );
113         attr_merge( e, "totalconnections", vals );
114
115         sprintf( buf, "%d", dtblsize );
116         val.bv_val = buf;
117         val.bv_len = strlen( buf );
118         attr_merge( e, "dtablesize", vals );
119
120         sprintf( buf, "%d", nwritewaiters );
121         val.bv_val = buf;
122         val.bv_len = strlen( buf );
123         attr_merge( e, "writewaiters", vals );
124
125         sprintf( buf, "%d", nreadwaiters );
126         val.bv_val = buf;
127         val.bv_len = strlen( buf );
128         attr_merge( e, "readwaiters", vals );
129
130 #ifdef LDAP_COUNTERS
131         sprintf( buf, "%ld", ops_initiated );
132         val.bv_val = buf;
133         val.bv_len = strlen( buf );
134         attr_merge( e, "opsinitiated", vals );
135
136         sprintf( buf, "%ld", ops_completed );
137         val.bv_val = buf;
138         val.bv_len = strlen( buf );
139         attr_merge( e, "opscompleted", vals );
140
141         sprintf( buf, "%ld", num_entries_sent );
142         val.bv_val = buf;
143         val.bv_len = strlen( buf );
144         attr_merge( e, "entriessent", vals );
145
146         sprintf( buf, "%ld", num_bytes_sent );
147         val.bv_val = buf;
148         val.bv_len = strlen( buf );
149         attr_merge( e, "bytessent", vals );
150 #endif
151
152         currenttime = slap_get_time();
153
154         ldap_pvt_thread_mutex_lock( &gmtime_mutex );
155 #ifndef LDAP_LOCALTIME
156         ltm = gmtime( &currenttime );
157         strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
158 #else
159         ltm = localtime( &currenttime );
160         strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
161 #endif
162         val.bv_val = buf;
163         val.bv_len = strlen( buf );
164         attr_merge( e, "currenttime", vals );
165
166 #ifndef LDAP_LOCALTIME
167         ltm = gmtime( &starttime );
168         strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
169 #else
170         ltm = localtime( &starttime );
171         strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
172 #endif
173         ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
174
175         val.bv_val = buf;
176         val.bv_len = strlen( buf );
177         attr_merge( e, "starttime", vals );
178
179         sprintf( buf, "%d", nbackends );
180         val.bv_val = buf;
181         val.bv_len = strlen( buf );
182         attr_merge( e, "nbackends", vals );
183
184 #ifdef HAVE_THREAD_CONCURRENCY
185         sprintf( buf, "%d", ldap_pvt_thread_get_concurrency() );
186         val.bv_val = buf;
187         val.bv_len = strlen( buf );
188         attr_merge( e, "concurrency", vals );
189 #endif
190
191         send_search_entry( &backends[0], conn, op, e, NULL, 0 );
192         send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
193
194         entry_free( e );
195 }
196
197 #endif /* slapd_monitor_dn */