1 /* sent.c - deal with data sent subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2005 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_SENT_BYTES = 0,
34 MONITOR_SENT_REFERRALS,
39 struct monitor_sent_t {
43 { BER_BVC("cn=Bytes"), BER_BVNULL },
44 { BER_BVC("cn=PDU"), BER_BVNULL },
45 { BER_BVC("cn=Entries"), BER_BVNULL },
46 { BER_BVC("cn=Referrals"), BER_BVNULL },
47 { BER_BVNULL, BER_BVNULL }
51 monitor_subsys_sent_init(
64 mi = ( monitor_info_t * )be->be_private;
66 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_sent ) ) {
67 Debug( LDAP_DEBUG_ANY,
68 "monitor_subsys_sent_init: "
69 "unable to get entry \"%s\"\n",
70 ms->mss_ndn.bv_val, 0, 0 );
74 mp = ( monitor_entry_t * )e_sent->e_private;
75 mp->mp_children = NULL;
76 ep = &mp->mp_children;
78 for ( i = 0; i < MONITOR_SENT_LAST; i++ ) {
79 char buf[ BACKMONITOR_BUFSIZE ];
80 struct berval nrdn, bv;
83 snprintf( buf, sizeof( buf ),
86 "structuralObjectClass: %s\n"
90 "createTimestamp: %s\n"
91 "modifyTimestamp: %s\n",
92 monitor_sent[ i ].rdn.bv_val,
94 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
95 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
96 &monitor_sent[ i ].rdn.bv_val[ STRLENOF( "cn=" ) ],
97 mi->mi_creatorsName.bv_val,
98 mi->mi_creatorsName.bv_val,
99 mi->mi_startTime.bv_val,
100 mi->mi_startTime.bv_val );
102 e = str2entry( buf );
104 Debug( LDAP_DEBUG_ANY,
105 "monitor_subsys_sent_init: "
106 "unable to create entry \"%s,%s\"\n",
107 monitor_sent[ i ].rdn.bv_val,
108 ms->mss_ndn.bv_val, 0 );
112 /* steal normalized RDN */
113 dnRdn( &e->e_nname, &nrdn );
114 ber_dupbv( &monitor_sent[ i ].nrdn, &nrdn );
116 BER_BVSTR( &bv, "0" );
117 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, &bv );
119 mp = monitor_entrypriv_create();
123 e->e_private = ( void * )mp;
125 mp->mp_flags = ms->mss_flags \
126 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
128 if ( monitor_cache_add( mi, e ) ) {
129 Debug( LDAP_DEBUG_ANY,
130 "monitor_subsys_sent_init: "
131 "unable to add entry \"%s,%s\"\n",
132 monitor_sent[ i ].rdn.bv_val,
133 ms->mss_ndn.bv_val, 0 );
141 monitor_cache_release( mi, e_sent );
147 monitor_subsys_sent_update(
152 monitor_info_t *mi = ( monitor_info_t *)op->o_bd->be_private;
162 dnRdn( &e->e_nname, &nrdn );
164 for ( i = 0; i < MONITOR_SENT_LAST; i++ ) {
165 if ( dn_match( &nrdn, &monitor_sent[ i ].nrdn ) ) {
170 if ( i == MONITOR_SENT_LAST ) {
171 return SLAP_CB_CONTINUE;
174 ldap_pvt_thread_mutex_lock(&slap_counters.sc_sent_mutex);
176 case MONITOR_SENT_ENTRIES:
177 ldap_pvt_mp_init_set( n, slap_counters.sc_entries );
180 case MONITOR_SENT_REFERRALS:
181 ldap_pvt_mp_init_set( n, slap_counters.sc_refs );
184 case MONITOR_SENT_PDU:
185 ldap_pvt_mp_init_set( n, slap_counters.sc_pdu );
188 case MONITOR_SENT_BYTES:
189 ldap_pvt_mp_init_set( n, slap_counters.sc_bytes );
195 ldap_pvt_thread_mutex_unlock(&slap_counters.sc_sent_mutex);
197 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
200 /* NOTE: no minus sign is allowed in the counters... */
201 UI2BV( &a->a_vals[ 0 ], n );
202 ldap_pvt_mp_clear( n );
204 /* FIXME: touch modifyTimestamp? */
206 return SLAP_CB_CONTINUE;