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_ENTRIES = 0,
32 MONITOR_SENT_REFERRALS,
39 struct monitor_sent_t {
43 { BER_BVC("cn=Entries"), BER_BVC("cn=entries") },
44 { BER_BVC("cn=Referrals"), BER_BVC("cn=referrals") },
45 { BER_BVC("cn=PDU"), BER_BVC("cn=pdu") },
46 { BER_BVC("cn=Bytes"), BER_BVC("cn=bytes") },
47 { BER_BVNULL, BER_BVNULL }
51 monitor_subsys_sent_init(
55 struct monitorinfo *mi;
57 Entry *e_tmp, *e_sent;
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%s%s",
70 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
77 for ( i = MONITOR_SENT_LAST; --i >= 0; ) {
78 char buf[ BACKMONITOR_BUFSIZE ];
82 snprintf( buf, sizeof( buf ),
85 "structuralObjectClass: %s\n"
89 "createTimestamp: %s\n"
90 "modifyTimestamp: %s\n",
91 monitor_sent[i].rdn.bv_val,
92 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
93 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
94 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
95 &monitor_sent[i].rdn.bv_val[STRLENOF( "cn=" )],
96 mi->mi_creatorsName.bv_val,
97 mi->mi_creatorsName.bv_val,
98 mi->mi_startTime.bv_val,
99 mi->mi_startTime.bv_val );
101 e = str2entry( buf );
103 Debug( LDAP_DEBUG_ANY,
104 "monitor_subsys_sent_init: "
105 "unable to create entry \"%s,%s\"\n",
106 monitor_sent[i].rdn.bv_val,
107 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0 );
113 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
115 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
116 e->e_private = ( void * )mp;
118 mp->mp_children = NULL;
119 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
120 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
121 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
123 if ( monitor_cache_add( mi, e ) ) {
124 Debug( LDAP_DEBUG_ANY,
125 "monitor_subsys_sent_init: "
126 "unable to add entry \"%s,%s\"\n%s%s",
127 monitor_sent[i].rdn.bv_val,
128 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0 );
135 mp = ( struct monitorentrypriv * )e_sent->e_private;
136 mp->mp_children = e_tmp;
138 monitor_cache_release( mi, e_sent );
144 monitor_subsys_sent_update(
149 struct monitorinfo *mi =
150 (struct monitorinfo *)op->o_bd->be_private;
155 char buf[] = "+9223372036854775807L";
161 dnRdn( &e->e_nname, &rdn );
163 for ( i = 0; i < MONITOR_SENT_LAST; i++ ) {
164 if ( dn_match( &rdn, &monitor_sent[i].nrdn ) ) {
169 if ( i == MONITOR_SENT_LAST ) {
173 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
175 case MONITOR_SENT_ENTRIES:
176 n = num_entries_sent;
179 case MONITOR_SENT_REFERRALS:
183 case MONITOR_SENT_PDU:
187 case MONITOR_SENT_BYTES:
194 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
196 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
201 snprintf( buf, sizeof( buf ), "%lu", n );
202 free( a->a_vals[ 0 ].bv_val );
203 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );