X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=bindings%2Fperl%2FCollectd.pm;h=cca349ec7a2c60e9a43dfa4b7030ce2299837d79;hb=92445ff3363441d0f515de4a3ab92a504cfc0366;hp=fc4a69dc8eb60c7810fa5a3d72ad30e98e73afbb;hpb=91da0566d4deed97ef6d122d02c7de8a8736a882;p=collectd.git diff --git a/bindings/perl/Collectd.pm b/bindings/perl/Collectd.pm index fc4a69dc..cca349ec 100644 --- a/bindings/perl/Collectd.pm +++ b/bindings/perl/Collectd.pm @@ -1,5 +1,5 @@ # collectd - Collectd.pm -# Copyright (C) 2007 Sebastian Harl +# Copyright (C) 2007, 2008 Sebastian Harl # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the @@ -42,6 +42,9 @@ our %EXPORT_TAGS = ( plugin_register plugin_unregister plugin_dispatch_values + plugin_flush + plugin_flush_one + plugin_flush_all plugin_dispatch_notification plugin_log ) ], @@ -52,6 +55,7 @@ our %EXPORT_TAGS = ( TYPE_SHUTDOWN TYPE_LOG TYPE_NOTIF + TYPE_FLUSH TYPE_DATASET ) ], 'ds_types' => [ qw( @@ -87,6 +91,10 @@ our %EXPORT_TAGS = ( foreach keys %EXPORT_TAGS; } +# global variables +our $hostname_g; +our $interval_g; + Exporter::export_ok_tags ('all'); my @plugins : shared = (); @@ -97,7 +105,8 @@ my %types = ( TYPE_WRITE, "write", TYPE_SHUTDOWN, "shutdown", TYPE_LOG, "log", - TYPE_NOTIF, "notify" + TYPE_NOTIF, "notify", + TYPE_FLUSH, "flush" ); foreach my $type (keys %types) { @@ -146,8 +155,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 +182,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 +195,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. " @@ -239,13 +251,12 @@ sub plugin_register { my %p : shared; - if ($data !~ m/^$pkg/) { + if ($data !~ m/^$pkg\:\:/) { $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, ); @@ -284,6 +295,34 @@ sub plugin_unregister { } } +sub plugin_flush { + my %args = @_; + + my $timeout = -1; + + DEBUG ("Collectd::plugin_flush:" + . (defined ($args{'timeout'}) ? " timeout = $args{'timeout'}" : "") + . (defined ($args{'plugins'}) ? " plugins = $args{'plugins'}" : "")); + + if (defined ($args{'timeout'}) && ($args{'timeout'} > 0)) { + $timeout = $args{'timeout'}; + } + + if (! defined $args{'plugins'}) { + plugin_flush_all ($timeout); + } + else { + if ("ARRAY" eq ref ($args{'plugins'})) { + foreach my $plugin (@{$args{'plugins'}}) { + plugin_flush_one ($timeout, $plugin); + } + } + else { + plugin_flush_one ($timeout, $args{'plugins'}); + } + } +} + 1; # vim: set sw=4 ts=4 tw=78 noexpandtab :