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_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(
55 struct monitorinfo *mi;
58 struct monitorentrypriv *mp;
63 mi = ( struct monitorinfo * )be->be_private;
65 if ( monitor_cache_get( mi,
66 &monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) {
67 Debug( LDAP_DEBUG_ANY,
68 "monitor_subsys_sent_init: "
69 "unable to get entry \"%s\"\n",
70 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
74 mp = ( struct monitorentrypriv * )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 rdn, 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,
93 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.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 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0 );
112 /* steal normalized RDN */
113 dnRdn( &e->e_nname, &rdn );
114 ber_dupbv( &monitor_sent[i].nrdn, &rdn );
116 BER_BVSTR( &bv, "0" );
117 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
119 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
120 e->e_private = ( void * )mp;
122 mp->mp_children = NULL;
123 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
124 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
125 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
127 if ( monitor_cache_add( mi, e ) ) {
128 Debug( LDAP_DEBUG_ANY,
129 "monitor_subsys_sent_init: "
130 "unable to add entry \"%s,%s\"\n",
131 monitor_sent[i].rdn.bv_val,
132 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0 );
140 monitor_cache_release( mi, e_sent );
146 monitor_subsys_sent_update(
151 struct monitorinfo *mi =
152 (struct monitorinfo *)op->o_bd->be_private;
157 #else /* ! HAVE_GMP */
159 #endif /* ! HAVE_GMP */
166 dnRdn( &e->e_nname, &rdn );
168 for ( i = 0; i < MONITOR_SENT_LAST; i++ ) {
169 if ( dn_match( &rdn, &monitor_sent[i].nrdn ) ) {
174 if ( i == MONITOR_SENT_LAST ) {
178 ldap_pvt_thread_mutex_lock(&slap_counters.sc_sent_mutex);
180 case MONITOR_SENT_ENTRIES:
182 mpz_init_set( n, slap_counters.sc_entries );
183 #else /* ! HAVE_GMP */
184 n = slap_counters.sc_entries;
185 #endif /* ! HAVE_GMP */
188 case MONITOR_SENT_REFERRALS:
190 mpz_init_set( n, slap_counters.sc_refs );
191 #else /* ! HAVE_GMP */
192 n = slap_counters.sc_refs;
193 #endif /* ! HAVE_GMP */
196 case MONITOR_SENT_PDU:
198 mpz_init_set( n, slap_counters.sc_pdu );
199 #else /* ! HAVE_GMP */
200 n = slap_counters.sc_pdu;
201 #endif /* ! HAVE_GMP */
204 case MONITOR_SENT_BYTES:
206 mpz_init_set( n, slap_counters.sc_bytes );
207 #else /* ! HAVE_GMP */
208 n = slap_counters.sc_bytes;
209 #endif /* ! HAVE_GMP */
215 ldap_pvt_thread_mutex_unlock(&slap_counters.sc_sent_mutex);
217 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
220 /* NOTE: no minus sign is allowed in the counters... */
221 UI2BV( &a->a_vals[ 0 ], n );
224 #endif /* HAVE_GMP */