1 /* sent.c - deal with data sent subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2006 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_destroy(
33 monitor_subsys_t *ms );
36 monitor_subsys_sent_update(
42 MONITOR_SENT_BYTES = 0,
45 MONITOR_SENT_REFERRALS,
50 struct monitor_sent_t {
54 { BER_BVC("cn=Bytes"), BER_BVNULL },
55 { BER_BVC("cn=PDU"), BER_BVNULL },
56 { BER_BVC("cn=Entries"), BER_BVNULL },
57 { BER_BVC("cn=Referrals"), BER_BVNULL },
58 { BER_BVNULL, BER_BVNULL }
62 monitor_subsys_sent_init(
64 monitor_subsys_t *ms )
74 ms->mss_destroy = monitor_subsys_sent_destroy;
75 ms->mss_update = monitor_subsys_sent_update;
77 mi = ( monitor_info_t * )be->be_private;
79 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_sent ) ) {
80 Debug( LDAP_DEBUG_ANY,
81 "monitor_subsys_sent_init: "
82 "unable to get entry \"%s\"\n",
83 ms->mss_ndn.bv_val, 0, 0 );
87 mp = ( monitor_entry_t * )e_sent->e_private;
88 mp->mp_children = NULL;
89 ep = &mp->mp_children;
91 for ( i = 0; i < MONITOR_SENT_LAST; i++ ) {
92 char buf[ BACKMONITOR_BUFSIZE ];
93 struct berval nrdn, bv;
96 snprintf( buf, sizeof( buf ),
99 "structuralObjectClass: %s\n"
102 "modifiersName: %s\n"
103 "createTimestamp: %s\n"
104 "modifyTimestamp: %s\n",
105 monitor_sent[ i ].rdn.bv_val,
107 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
108 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
109 &monitor_sent[ i ].rdn.bv_val[ STRLENOF( "cn=" ) ],
110 mi->mi_creatorsName.bv_val,
111 mi->mi_creatorsName.bv_val,
112 mi->mi_startTime.bv_val,
113 mi->mi_startTime.bv_val );
115 e = str2entry( buf );
117 Debug( LDAP_DEBUG_ANY,
118 "monitor_subsys_sent_init: "
119 "unable to create entry \"%s,%s\"\n",
120 monitor_sent[ i ].rdn.bv_val,
121 ms->mss_ndn.bv_val, 0 );
125 /* steal normalized RDN */
126 dnRdn( &e->e_nname, &nrdn );
127 ber_dupbv( &monitor_sent[ i ].nrdn, &nrdn );
129 BER_BVSTR( &bv, "0" );
130 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, &bv );
132 mp = monitor_entrypriv_create();
136 e->e_private = ( void * )mp;
138 mp->mp_flags = ms->mss_flags \
139 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
141 if ( monitor_cache_add( mi, e ) ) {
142 Debug( LDAP_DEBUG_ANY,
143 "monitor_subsys_sent_init: "
144 "unable to add entry \"%s,%s\"\n",
145 monitor_sent[ i ].rdn.bv_val,
146 ms->mss_ndn.bv_val, 0 );
154 monitor_cache_release( mi, e_sent );
160 monitor_subsys_sent_destroy(
162 monitor_subsys_t *ms )
166 for ( i = 0; i < MONITOR_SENT_LAST; i++ ) {
167 if ( !BER_BVISNULL( &monitor_sent[ i ].nrdn ) ) {
168 ch_free( monitor_sent[ i ].nrdn.bv_val );
176 monitor_subsys_sent_update(
181 monitor_info_t *mi = ( monitor_info_t *)op->o_bd->be_private;
188 assert( mi != NULL );
191 dnRdn( &e->e_nname, &nrdn );
193 for ( i = 0; i < MONITOR_SENT_LAST; i++ ) {
194 if ( dn_match( &nrdn, &monitor_sent[ i ].nrdn ) ) {
199 if ( i == MONITOR_SENT_LAST ) {
200 return SLAP_CB_CONTINUE;
203 ldap_pvt_thread_mutex_lock(&slap_counters.sc_sent_mutex);
205 case MONITOR_SENT_ENTRIES:
206 ldap_pvt_mp_init_set( n, slap_counters.sc_entries );
209 case MONITOR_SENT_REFERRALS:
210 ldap_pvt_mp_init_set( n, slap_counters.sc_refs );
213 case MONITOR_SENT_PDU:
214 ldap_pvt_mp_init_set( n, slap_counters.sc_pdu );
217 case MONITOR_SENT_BYTES:
218 ldap_pvt_mp_init_set( n, slap_counters.sc_bytes );
224 ldap_pvt_thread_mutex_unlock(&slap_counters.sc_sent_mutex);
226 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
229 /* NOTE: no minus sign is allowed in the counters... */
230 UI2BV( &a->a_vals[ 0 ], n );
231 ldap_pvt_mp_clear( n );
233 /* FIXME: touch modifyTimestamp? */
235 return SLAP_CB_CONTINUE;