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