[collectd] perl plugin: counter values > 2^31-1?

Chris Buben cbuben at eventlogic.com
Thu Feb 25 12:26:21 CET 2010


Hi all,

I ran into this scenario with a perl write plugin:

rhel5 i386, collectd 4.9.1

$ uname -a
Linux myhost 2.6.18-92.el5PAE #1 SMP Tue Apr 29 13:31:02 EDT 2008 i686
i686 i386 GNU/Linux

1) A read plugin submits a counter value > 2^31-1
2) When my perl write plugin sees value list, the value coming out is
interpreted as a signed 32-bit integer, i.e. wrapped negative.

I'm no perl wizard, but seeing newSViv in value_list2hv in perl.c:652
makes me think this will be the expected behavior for COUNTER, DERIVE,
and ABSOLUTE on 32-bit systems.  This issue should be ok on 64-bit
systems (disregarding some possible sign surprises for COUNTER and
ABSOLUTE due to SViv, not SVuv?) as an IV is guaranteed to hold a
pointer...

===> Is there any way/reason/desire to make counter value
representation consistent in perl across 32 and 64 bit systems?  I'll
do some homework and see Net::SNMP's approach (but at a more
reasonable hour)

Thanks,

- C

------------------------------
Plugin code
------------------------------

package Collectd::Plugin::CounterTest;
use strict;
use warnings;
use Collectd qw( :all );

plugin_register (TYPE_WRITE, 'CounterTest', 'countertest_write');

sub countertest_write {
    my $type = shift;
    my $ds   = shift;
    my $vl   = shift;

    if($vl->{'type_instance'} eq 'countertest') {
        plugin_log(LOG_ERR, "CounterTest: " . $vl->{'values'}->[0]);
    }

    return 1;
}

1;

------------------------------
Submit two counter values, 2^31-1, then 2^31
------------------------------
$ nc -U /var/run/collectd/collectd-unixsock <<< "PUTVAL
$HOSTNAME/nada/counter-countertest N:$(bc <<< 2^31-1)"
0 Success: 1 value has been dispatched.
$ nc -U /var/run/collectd/collectd-unixsock <<< "PUTVAL
$HOSTNAME/nada/counter-countertest N:$(bc <<< 2^31)"
0 Success: 1 value has been dispatched.

in syslog...
Feb 25 05:06:41 myhost collectd[24475]: CounterTest: 2147483647
Feb 25 05:06:44 myhost collectd[24475]: CounterTest: -2147483648



More information about the collectd mailing list