[collectd] [PATCH] Collectd.pm: Use $interval_g instead of a hard-coded value.

Sebastian Harl sh at tokkee.org
Tue Jan 29 02:12:17 CET 2008


The hard-coded value was still legacy code from the time before the global
variables have been exported to Perl.

Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 bindings/perl/Collectd.pm |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/bindings/perl/Collectd.pm b/bindings/perl/Collectd.pm
index fc4a69d..4377570 100644
--- a/bindings/perl/Collectd.pm
+++ b/bindings/perl/Collectd.pm
@@ -87,6 +87,10 @@ our %EXPORT_TAGS = (
 		foreach keys %EXPORT_TAGS;
 }
 
+# global variables
+our $hostname_g;
+our $interval_g;
+
 Exporter::export_ok_tags ('all');
 
 my @plugins : shared = ();
@@ -146,8 +150,7 @@ sub plugin_call_all {
 		my $status = 0;
 
 		if ($p->{'wait_left'} > 0) {
-			# TODO: use interval_g
-			$p->{'wait_left'} -= 10;
+			$p->{'wait_left'} -= $interval_g;
 		}
 
 		next if ($p->{'wait_left'} > 0);
@@ -174,11 +177,12 @@ sub plugin_call_all {
 
 		if ($status) {
 			$p->{'wait_left'} = 0;
-			$p->{'wait_time'} = 10;
+			$p->{'wait_time'} = $interval_g;
 		}
 		elsif (TYPE_READ == $type) {
-			WARNING ("${plugin}->read() failed with status $status. "
-				. "Will suspend it for $p->{'wait_left'} seconds.");
+			if ($p->{'wait_time'} < $interval_g) {
+				$p->{'wait_time'} = $interval_g;
+			}
 
 			$p->{'wait_left'} = $p->{'wait_time'};
 			$p->{'wait_time'} *= 2;
@@ -186,6 +190,9 @@ sub plugin_call_all {
 			if ($p->{'wait_time'} > 86400) {
 				$p->{'wait_time'} = 86400;
 			}
+
+			WARNING ("${plugin}->read() failed with status $status. "
+				. "Will suspend it for $p->{'wait_left'} seconds.");
 		}
 		elsif (TYPE_INIT == $type) {
 			ERROR ("${plugin}->init() failed with status $status. "
@@ -243,9 +250,8 @@ sub plugin_register {
 			$data = $pkg . "::" . $data;
 		}
 
-		# TODO: make interval_g available at configuration time
 		%p = (
-			wait_time => 10,
+			wait_time => $interval_g,
 			wait_left => 0,
 			cb_name   => $data,
 		);
-- 
1.5.4.rc4.23.gcab31

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080129/f70e4e2d/attachment.pgp 


More information about the collectd mailing list