From: Florian Forster Date: Sat, 19 May 2007 11:59:10 +0000 (+0200) Subject: Collectd::Unixsock: Handle instance `0' and interpret a returned `NaN' correctly. X-Git-Tag: collectd-4.0.0-rc10~9 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1426fa96cba8d8e4fad5594a210c4a5d7536966f;p=collectd.git Collectd::Unixsock: Handle instance `0' and interpret a returned `NaN' correctly. --- diff --git a/contrib/PerlLib/Collectd/Unixsock.pm b/contrib/PerlLib/Collectd/Unixsock.pm index b6814f8d..92e8772c 100644 --- a/contrib/PerlLib/Collectd/Unixsock.pm +++ b/contrib/PerlLib/Collectd/Unixsock.pm @@ -76,9 +76,9 @@ sub _create_identifier $host = $args->{'host'}; $plugin = $args->{'plugin'}; - $plugin .= '-' . $args->{'plugin_instance'} if ($args->{'plugin_instance'}); + $plugin .= '-' . $args->{'plugin_instance'} if (defined ($args->{'plugin_instance'})); $type = $args->{'type'}; - $type .= '-' . $args->{'type_instance'} if ($args->{'type_instance'}); + $type .= '-' . $args->{'type_instance'} if (defined ($args->{'type_instance'})); return ("$host/$plugin/$type"); } # _create_identifier @@ -133,10 +133,12 @@ sub getval $identifier = _create_identifier (\%args) or return; $msg = "GETVAL $identifier\n"; + #print "-> $msg"; send ($fh, $msg, 0) or confess ("send: $!"); $msg = undef; recv ($fh, $msg, 1024, 0) or confess ("recv: $!"); + #print "<- $msg"; ($status, $msg) = split (' ', $msg, 2); if ($status <= 0) @@ -148,7 +150,11 @@ sub getval for (split (' ', $msg)) { my $entry = $_; - if ($entry =~ m/^(\w+)=($RE{num}{real})$/) + if ($entry =~ m/^(\w+)=NaN$/) + { + $ret->{$1} = undef; + } + elsif ($entry =~ m/^(\w+)=($RE{num}{real})$/) { $ret->{$1} = 0.0 + $2; } @@ -198,9 +204,11 @@ sub putval } $msg = "PUTVAL $identifier $values\n"; + #print "-> $msg"; send ($fh, $msg, 0) or confess ("send: $!"); $msg = undef; recv ($fh, $msg, 1024, 0) or confess ("recv: $!"); + #print "<- $msg"; ($status, $msg) = split (' ', $msg, 2); return (1) if ($status == 0);