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"
75 "createTimestamp: %s\n"
76 "modifyTimestamp: %s\n",
77 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
78 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
79 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
80 mi->mi_creatorsName.bv_val,
81 mi->mi_creatorsName.bv_val,
82 mi->mi_startTime.bv_val,
83 mi->mi_startTime.bv_val );
88 LDAP_LOG( OPERATION, CRIT,
89 "monitor_subsys_sent_init: "
90 "unable to create entry 'cn=Entries,%s'\n",
91 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
93 Debug( LDAP_DEBUG_ANY,
94 "monitor_subsys_sent_init: "
95 "unable to create entry 'cn=Entries,%s'\n%s%s",
96 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
104 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
106 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
107 e->e_private = ( void * )mp;
109 mp->mp_children = NULL;
110 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
111 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
112 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
114 if ( monitor_cache_add( mi, e ) ) {
116 LDAP_LOG( OPERATION, CRIT,
117 "monitor_subsys_sent_init: "
118 "unable to add entry 'cn=Entries,%s'\n",
119 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
121 Debug( LDAP_DEBUG_ANY,
122 "monitor_subsys_sent_init: "
123 "unable to add entry 'cn=Entries,%s'\n%s%s",
124 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
135 snprintf( buf, sizeof( buf ),
136 "dn: cn=Referrals,%s\n"
138 "structuralObjectClass: %s\n"
141 "modifiersName: %s\n"
142 "createTimestamp: %s\n"
143 "modifyTimestamp: %s\n",
144 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
145 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
146 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
147 mi->mi_creatorsName.bv_val,
148 mi->mi_creatorsName.bv_val,
149 mi->mi_startTime.bv_val,
150 mi->mi_startTime.bv_val );
152 e = str2entry( buf );
155 LDAP_LOG( OPERATION, CRIT,
156 "monitor_subsys_sent_init: "
157 "unable to create entry 'cn=Referrals,%s'\n",
158 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
160 Debug( LDAP_DEBUG_ANY,
161 "monitor_subsys_sent_init: "
162 "unable to create entry 'cn=Referrals,%s'\n%s%s",
163 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
171 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
173 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
174 e->e_private = ( void * )mp;
176 mp->mp_children = NULL;
177 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
178 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
179 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
181 if ( monitor_cache_add( mi, e ) ) {
183 LDAP_LOG( OPERATION, CRIT,
184 "monitor_subsys_sent_init: "
185 "unable to add entry 'cn=Referrals,%s'\n",
186 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
188 Debug( LDAP_DEBUG_ANY,
189 "monitor_subsys_sent_init: "
190 "unable to add entry 'cn=Referrals,%s'\n%s%s",
191 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
202 snprintf( buf, sizeof( buf ),
205 "structuralObjectClass: %s\n"
208 "modifiersName: %s\n"
209 "createTimestamp: %s\n"
210 "modifyTimestamp: %s\n",
211 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
212 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
213 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
214 mi->mi_creatorsName.bv_val,
215 mi->mi_creatorsName.bv_val,
216 mi->mi_startTime.bv_val,
217 mi->mi_startTime.bv_val );
219 e = str2entry( buf );
222 LDAP_LOG( OPERATION, CRIT,
223 "monitor_subsys_sent_init: "
224 "unable to create entry 'cn=PDU,%s'\n",
225 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
227 Debug( LDAP_DEBUG_ANY,
228 "monitor_subsys_sent_init: "
229 "unable to create entry 'cn=PDU,%s'\n%s%s",
230 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
238 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
240 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
241 e->e_private = ( void * )mp;
243 mp->mp_children = NULL;
244 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
245 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
246 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
248 if ( monitor_cache_add( mi, e ) ) {
250 LDAP_LOG( OPERATION, CRIT,
251 "monitor_subsys_sent_init: "
252 "unable to add entry 'cn=PDU,%s'\n",
253 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
255 Debug( LDAP_DEBUG_ANY,
256 "monitor_subsys_sent_init: "
257 "unable to add entry 'cn=PDU,%s'\n%s%s",
258 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
269 snprintf( buf, sizeof( buf ),
272 "structuralObjectClass: %s\n"
275 "modifiersName: %s\n"
276 "createTimestamp: %s\n"
277 "modifyTimestamp: %s\n",
278 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
279 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
280 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
281 mi->mi_creatorsName.bv_val,
282 mi->mi_creatorsName.bv_val,
283 mi->mi_startTime.bv_val,
284 mi->mi_startTime.bv_val );
286 e = str2entry( buf );
289 LDAP_LOG( OPERATION, CRIT,
290 "monitor_subsys_sent_init: "
291 "unable to create entry 'cn=Bytes,%s'\n",
292 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
294 Debug( LDAP_DEBUG_ANY,
295 "monitor_subsys_sent_init: "
296 "unable to create entry 'cn=Bytes,%s'\n%s%s",
297 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
305 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
307 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
308 e->e_private = ( void * )mp;
310 mp->mp_children = NULL;
311 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
312 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
313 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
315 if ( monitor_cache_add( mi, e ) ) {
317 LDAP_LOG( OPERATION, CRIT,
318 "monitor_subsys_sent_init: "
319 "unable to add entry 'cn=Bytes,%s'\n",
320 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
322 Debug( LDAP_DEBUG_ANY,
323 "monitor_subsys_sent_init: "
324 "unable to add entry 'cn=Bytes,%s'\n%s%s",
325 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
333 mp = ( struct monitorentrypriv * )e_sent->e_private;
334 mp->mp_children = e_tmp;
336 monitor_cache_release( mi, e_sent );
342 monitor_subsys_sent_update(
347 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
353 if ( strncasecmp( e->e_ndn, "cn=entries",
354 sizeof("cn=entries")-1 ) == 0 ) {
355 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
356 n = num_entries_sent;
357 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
359 } else if ( strncasecmp( e->e_ndn, "cn=referrals",
360 sizeof("cn=referrals")-1 ) == 0 ) {
361 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
363 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
365 } else if ( strncasecmp( e->e_ndn, "cn=pdu",
366 sizeof("cn=pdu")-1 ) == 0 ) {
367 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
369 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
371 } else if ( strncasecmp( e->e_ndn, "cn=bytes",
372 sizeof("cn=bytes")-1 ) == 0 ) {
373 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
375 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
380 char buf[] = "+9223372036854775807L";
382 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter);
387 snprintf( buf, sizeof( buf ), "%ld", n );
388 free( a->a_vals[ 0 ].bv_val );
389 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );