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 ) ) {
48 Debug( LDAP_DEBUG_ANY,
49 "monitor_subsys_sent_init: "
50 "unable to get entry '%s'\n%s%s",
51 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
61 snprintf( buf, sizeof( buf ),
64 "structuralObjectClass: %s\n"
68 "createTimestamp: %s\n"
69 "modifyTimestamp: %s\n",
70 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
71 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
72 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
73 mi->mi_creatorsName.bv_val,
74 mi->mi_creatorsName.bv_val,
75 mi->mi_startTime.bv_val,
76 mi->mi_startTime.bv_val );
80 Debug( LDAP_DEBUG_ANY,
81 "monitor_subsys_sent_init: "
82 "unable to create entry 'cn=Entries,%s'\n%s%s",
83 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
90 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
92 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
93 e->e_private = ( void * )mp;
95 mp->mp_children = NULL;
96 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
97 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
98 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
100 if ( monitor_cache_add( mi, e ) ) {
101 Debug( LDAP_DEBUG_ANY,
102 "monitor_subsys_sent_init: "
103 "unable to add entry 'cn=Entries,%s'\n%s%s",
104 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
114 snprintf( buf, sizeof( buf ),
115 "dn: cn=Referrals,%s\n"
117 "structuralObjectClass: %s\n"
120 "modifiersName: %s\n"
121 "createTimestamp: %s\n"
122 "modifyTimestamp: %s\n",
123 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
124 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
125 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
126 mi->mi_creatorsName.bv_val,
127 mi->mi_creatorsName.bv_val,
128 mi->mi_startTime.bv_val,
129 mi->mi_startTime.bv_val );
131 e = str2entry( buf );
133 Debug( LDAP_DEBUG_ANY,
134 "monitor_subsys_sent_init: "
135 "unable to create entry 'cn=Referrals,%s'\n%s%s",
136 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
143 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
145 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
146 e->e_private = ( void * )mp;
148 mp->mp_children = NULL;
149 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
150 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
151 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
153 if ( monitor_cache_add( mi, e ) ) {
154 Debug( LDAP_DEBUG_ANY,
155 "monitor_subsys_sent_init: "
156 "unable to add entry 'cn=Referrals,%s'\n%s%s",
157 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
167 snprintf( buf, sizeof( buf ),
170 "structuralObjectClass: %s\n"
173 "modifiersName: %s\n"
174 "createTimestamp: %s\n"
175 "modifyTimestamp: %s\n",
176 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
177 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
178 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
179 mi->mi_creatorsName.bv_val,
180 mi->mi_creatorsName.bv_val,
181 mi->mi_startTime.bv_val,
182 mi->mi_startTime.bv_val );
184 e = str2entry( buf );
186 Debug( LDAP_DEBUG_ANY,
187 "monitor_subsys_sent_init: "
188 "unable to create entry 'cn=PDU,%s'\n%s%s",
189 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
196 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
198 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
199 e->e_private = ( void * )mp;
201 mp->mp_children = NULL;
202 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
203 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
204 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
206 if ( monitor_cache_add( mi, e ) ) {
207 Debug( LDAP_DEBUG_ANY,
208 "monitor_subsys_sent_init: "
209 "unable to add entry 'cn=PDU,%s'\n%s%s",
210 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
220 snprintf( buf, sizeof( buf ),
223 "structuralObjectClass: %s\n"
226 "modifiersName: %s\n"
227 "createTimestamp: %s\n"
228 "modifyTimestamp: %s\n",
229 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
230 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
231 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
232 mi->mi_creatorsName.bv_val,
233 mi->mi_creatorsName.bv_val,
234 mi->mi_startTime.bv_val,
235 mi->mi_startTime.bv_val );
237 e = str2entry( buf );
239 Debug( LDAP_DEBUG_ANY,
240 "monitor_subsys_sent_init: "
241 "unable to create entry 'cn=Bytes,%s'\n%s%s",
242 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
249 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
251 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
252 e->e_private = ( void * )mp;
254 mp->mp_children = NULL;
255 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
256 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
257 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
259 if ( monitor_cache_add( mi, e ) ) {
260 Debug( LDAP_DEBUG_ANY,
261 "monitor_subsys_sent_init: "
262 "unable to add entry 'cn=Bytes,%s'\n%s%s",
263 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
270 mp = ( struct monitorentrypriv * )e_sent->e_private;
271 mp->mp_children = e_tmp;
273 monitor_cache_release( mi, e_sent );
279 monitor_subsys_sent_update(
284 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
290 if ( strncasecmp( e->e_ndn, "cn=entries",
291 sizeof("cn=entries")-1 ) == 0 ) {
292 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
293 n = num_entries_sent;
294 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
296 } else if ( strncasecmp( e->e_ndn, "cn=referrals",
297 sizeof("cn=referrals")-1 ) == 0 ) {
298 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
300 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
302 } else if ( strncasecmp( e->e_ndn, "cn=pdu",
303 sizeof("cn=pdu")-1 ) == 0 ) {
304 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
306 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
308 } else if ( strncasecmp( e->e_ndn, "cn=bytes",
309 sizeof("cn=bytes")-1 ) == 0 ) {
310 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
312 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
317 char buf[] = "+9223372036854775807L";
319 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter);
324 snprintf( buf, sizeof( buf ), "%ld", n );
325 free( a->a_vals[ 0 ].bv_val );
326 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );