]> git.sur5r.net Git - openldap/blob - servers/slapd/monitor.c
use auth sockbuf max
[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 <stdio.h>
14 #include <string.h>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include "slap.h"
18 #include "ldapconfig.h"
19
20 #if defined( SLAPD_MONITOR_DN )
21
22 extern int              nbackends;
23 extern Backend          *backends;
24 extern int              active_threads;
25 extern int              dtblsize;
26 extern Connection       *c;
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;
33 extern int              num_conns;
34
35
36 extern char Versionstr[];
37
38 /*
39  * no mutex protection in here - take our chances!
40  */
41
42 void
43 monitor_info( Connection *conn, Operation *op )
44 {
45         Entry           *e;
46         char            buf[BUFSIZ], buf2[20];
47         struct berval   val;
48         struct berval   *vals[2];
49         int             i, nconns, nwritewaiters, nreadwaiters;
50         struct tm       *ltm;
51         char            *p, *tmpdn;
52
53         vals[0] = &val;
54         vals[1] = NULL;
55
56         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
57         e->e_attrs = NULL;
58         e->e_dn = strdup( SLAPD_MONITOR_DN );
59
60         val.bv_val = Versionstr;
61         if (( p = strchr( Versionstr, '\n' )) == NULL ) {
62                 val.bv_len = strlen( Versionstr );
63         } else {
64                 val.bv_len = p - Versionstr;
65         }
66         attr_merge( e, "version", vals );
67
68         sprintf( buf, "%d", active_threads );
69         val.bv_val = buf;
70         val.bv_len = strlen( buf );
71         attr_merge( e, "threads", vals );
72
73         nconns = 0;
74         nwritewaiters = 0;
75         nreadwaiters = 0;
76         for ( i = 0; i < dtblsize; i++ ) {
77                 if ( c[i].c_sb.sb_sd != -1 ) {
78                         nconns++;
79                         if ( c[i].c_writewaiter ) {
80                                 nwritewaiters++;
81                         }
82                         if ( c[i].c_gettingber ) {
83                                 nreadwaiters++;
84                         }
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 );
94                         val.bv_val = buf;
95                         val.bv_len = strlen( buf );
96                         attr_merge( e, "connection", vals );
97                 }
98         }
99         sprintf( buf, "%d", nconns );
100         val.bv_val = buf;
101         val.bv_len = strlen( buf );
102         attr_merge( e, "currentconnections", vals );
103
104         sprintf( buf, "%d", num_conns );
105         val.bv_val = buf;
106         val.bv_len = strlen( buf );
107         attr_merge( e, "totalconnections", vals );
108
109         sprintf( buf, "%d", dtblsize );
110         val.bv_val = buf;
111         val.bv_len = strlen( buf );
112         attr_merge( e, "dtablesize", vals );
113
114         sprintf( buf, "%d", nwritewaiters );
115         val.bv_val = buf;
116         val.bv_len = strlen( buf );
117         attr_merge( e, "writewaiters", vals );
118
119         sprintf( buf, "%d", nreadwaiters );
120         val.bv_val = buf;
121         val.bv_len = strlen( buf );
122         attr_merge( e, "readwaiters", vals );
123
124         sprintf( buf, "%ld", ops_initiated );
125         val.bv_val = buf;
126         val.bv_len = strlen( buf );
127         attr_merge( e, "opsinitiated", vals );
128
129         sprintf( buf, "%ld", ops_completed );
130         val.bv_val = buf;
131         val.bv_len = strlen( buf );
132         attr_merge( e, "opscompleted", vals );
133
134         sprintf( buf, "%ld", num_entries_sent );
135         val.bv_val = buf;
136         val.bv_len = strlen( buf );
137         attr_merge( e, "entriessent", vals );
138
139         sprintf( buf, "%ld", num_bytes_sent );
140         val.bv_val = buf;
141         val.bv_len = strlen( buf );
142         attr_merge( e, "bytessent", vals );
143
144         ltm = localtime( &currenttime );
145         strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
146         val.bv_val = buf;
147         val.bv_len = strlen( buf );
148         attr_merge( e, "currenttime", vals );
149
150         ltm = localtime( &starttime );
151         strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
152         val.bv_val = buf;
153         val.bv_len = strlen( buf );
154         attr_merge( e, "starttime", vals );
155
156         sprintf( buf, "%d", nbackends );
157         val.bv_val = buf;
158         val.bv_len = strlen( buf );
159         attr_merge( e, "nbackends", vals );
160
161 #ifdef THREAD_SUNOS5_LWP
162         sprintf( buf, "%d", thr_getconcurrency() );
163         val.bv_val = buf;
164         val.bv_len = strlen( buf );
165         attr_merge( e, "concurrency", vals );
166 #endif
167
168         send_search_entry( &backends[0], conn, op, e, NULL, 0 );
169         send_ldap_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, 1 );
170
171         entry_free( e );
172 }
173
174 #endif /* slapd_monitor_dn */