1 /* sent.c - deal with data sent subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2004 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
28 #include "back-monitor.h"
31 monitor_subsys_sent_init(
35 struct monitorinfo *mi;
37 Entry *e, *e_tmp, *e_sent;
38 struct monitorentrypriv *mp;
39 char buf[ BACKMONITOR_BUFSIZE ];
44 mi = ( struct monitorinfo * )be->be_private;
46 if ( monitor_cache_get( mi,
47 &monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) {
49 LDAP_LOG( OPERATION, CRIT,
50 "monitor_subsys_sent_init: "
51 "unable to get entry '%s'\n",
52 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
54 Debug( LDAP_DEBUG_ANY,
55 "monitor_subsys_sent_init: "
56 "unable to get entry '%s'\n%s%s",
57 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
68 snprintf( buf, sizeof( buf ),
71 "structuralObjectClass: %s\n"
73 "createTimestamp: %s\n"
74 "modifyTimestamp: %s\n",
75 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
76 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
77 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
78 mi->mi_startTime.bv_val,
79 mi->mi_startTime.bv_val );
84 LDAP_LOG( OPERATION, CRIT,
85 "monitor_subsys_sent_init: "
86 "unable to create entry 'cn=Entries,%s'\n",
87 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
89 Debug( LDAP_DEBUG_ANY,
90 "monitor_subsys_sent_init: "
91 "unable to create entry 'cn=Entries,%s'\n%s%s",
92 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
100 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
102 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
103 e->e_private = ( void * )mp;
105 mp->mp_children = NULL;
106 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
107 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
108 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
110 if ( monitor_cache_add( mi, e ) ) {
112 LDAP_LOG( OPERATION, CRIT,
113 "monitor_subsys_sent_init: "
114 "unable to add entry 'cn=Entries,%s'\n",
115 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
117 Debug( LDAP_DEBUG_ANY,
118 "monitor_subsys_sent_init: "
119 "unable to add entry 'cn=Entries,%s'\n%s%s",
120 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
131 snprintf( buf, sizeof( buf ),
132 "dn: cn=Referrals,%s\n"
134 "structuralObjectClass: %s\n"
136 "createTimestamp: %s\n"
137 "modifyTimestamp: %s\n",
138 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
139 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
140 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
141 mi->mi_startTime.bv_val,
142 mi->mi_startTime.bv_val );
144 e = str2entry( buf );
147 LDAP_LOG( OPERATION, CRIT,
148 "monitor_subsys_sent_init: "
149 "unable to create entry 'cn=Referrals,%s'\n",
150 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
152 Debug( LDAP_DEBUG_ANY,
153 "monitor_subsys_sent_init: "
154 "unable to create entry 'cn=Referrals,%s'\n%s%s",
155 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
163 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
165 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
166 e->e_private = ( void * )mp;
168 mp->mp_children = NULL;
169 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
170 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
171 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
173 if ( monitor_cache_add( mi, e ) ) {
175 LDAP_LOG( OPERATION, CRIT,
176 "monitor_subsys_sent_init: "
177 "unable to add entry 'cn=Referrals,%s'\n",
178 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
180 Debug( LDAP_DEBUG_ANY,
181 "monitor_subsys_sent_init: "
182 "unable to add entry 'cn=Referrals,%s'\n%s%s",
183 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
194 snprintf( buf, sizeof( buf ),
197 "structuralObjectClass: %s\n"
199 "createTimestamp: %s\n"
200 "modifyTimestamp: %s\n",
201 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
202 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
203 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
204 mi->mi_startTime.bv_val,
205 mi->mi_startTime.bv_val );
207 e = str2entry( buf );
210 LDAP_LOG( OPERATION, CRIT,
211 "monitor_subsys_sent_init: "
212 "unable to create entry 'cn=PDU,%s'\n",
213 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
215 Debug( LDAP_DEBUG_ANY,
216 "monitor_subsys_sent_init: "
217 "unable to create entry 'cn=PDU,%s'\n%s%s",
218 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
226 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
228 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
229 e->e_private = ( void * )mp;
231 mp->mp_children = NULL;
232 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
233 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
234 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
236 if ( monitor_cache_add( mi, e ) ) {
238 LDAP_LOG( OPERATION, CRIT,
239 "monitor_subsys_sent_init: "
240 "unable to add entry 'cn=PDU,%s'\n",
241 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
243 Debug( LDAP_DEBUG_ANY,
244 "monitor_subsys_sent_init: "
245 "unable to add entry 'cn=PDU,%s'\n%s%s",
246 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
257 snprintf( buf, sizeof( buf ),
260 "structuralObjectClass: %s\n"
262 "createTimestamp: %s\n"
263 "modifyTimestamp: %s\n",
264 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
265 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
266 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
267 mi->mi_startTime.bv_val,
268 mi->mi_startTime.bv_val );
270 e = str2entry( buf );
273 LDAP_LOG( OPERATION, CRIT,
274 "monitor_subsys_sent_init: "
275 "unable to create entry 'cn=Bytes,%s'\n",
276 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
278 Debug( LDAP_DEBUG_ANY,
279 "monitor_subsys_sent_init: "
280 "unable to create entry 'cn=Bytes,%s'\n%s%s",
281 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
289 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
291 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
292 e->e_private = ( void * )mp;
294 mp->mp_children = NULL;
295 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
296 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
297 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
299 if ( monitor_cache_add( mi, e ) ) {
301 LDAP_LOG( OPERATION, CRIT,
302 "monitor_subsys_sent_init: "
303 "unable to add entry 'cn=Bytes,%s'\n",
304 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
306 Debug( LDAP_DEBUG_ANY,
307 "monitor_subsys_sent_init: "
308 "unable to add entry 'cn=Bytes,%s'\n%s%s",
309 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
317 mp = ( struct monitorentrypriv * )e_sent->e_private;
318 mp->mp_children = e_tmp;
320 monitor_cache_release( mi, e_sent );
326 monitor_subsys_sent_update(
331 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
337 if ( strncasecmp( e->e_ndn, "cn=entries",
338 sizeof("cn=entries")-1 ) == 0 ) {
339 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
340 n = num_entries_sent;
341 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
343 } else if ( strncasecmp( e->e_ndn, "cn=referrals",
344 sizeof("cn=referrals")-1 ) == 0 ) {
345 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
347 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
349 } else if ( strncasecmp( e->e_ndn, "cn=pdu",
350 sizeof("cn=pdu")-1 ) == 0 ) {
351 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
353 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
355 } else if ( strncasecmp( e->e_ndn, "cn=bytes",
356 sizeof("cn=bytes")-1 ) == 0 ) {
357 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
359 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
364 char buf[] = "+9223372036854775807L";
366 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter);
371 snprintf( buf, sizeof( buf ), "%ld", n );
372 free( a->a_vals[ 0 ].bv_val );
373 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );