From: Sebastian Harl Date: Sun, 27 Apr 2008 18:56:09 +0000 (+0200) Subject: perl plugin: Exported plugin_flush*() to Perl. X-Git-Tag: collectd-4.4.0~27 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=99c9ed11143554e045e931f643b7b8d30e092d76;p=collectd.git perl plugin: Exported plugin_flush*() to Perl. This adds the following functions to collectd's Perl API which flush the given plugins using the given interval. * Collectd::plugin_flush: This function is a frontend to _flush_one() and _flush_all() and expects up to two named parameters: - timeout => $timeout - name => $name or [ $name1, $name2, ... ] * Collectd::plugin_flush_one: This function expects exactly two parameters, namely the timeout and the plugin name. * Collectd::plugin_flush_all: This function expects a single parameter, namely the timeout. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- diff --git a/bindings/perl/Collectd.pm b/bindings/perl/Collectd.pm index 399fca84..ee265e80 100644 --- a/bindings/perl/Collectd.pm +++ b/bindings/perl/Collectd.pm @@ -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 ) ], @@ -292,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{'name'}) ? " name = $args{'name'}" : "")); + + if (defined ($args{'timeout'}) && ($args{'timeout'} > 0)) { + $timeout = $args{'timeout'}; + } + + if (! defined $args{'name'}) { + plugin_flush_all ($timeout); + } + else { + if ("ARRAY" eq ref ($args{'name'})) { + foreach my $name (@{$args{'name'}}) { + plugin_flush_one ($timeout, $name); + } + } + else { + plugin_flush_one ($timeout, $args{'name'}); + } + } +} + 1; # vim: set sw=4 ts=4 tw=78 noexpandtab : diff --git a/src/perl.c b/src/perl.c index beea288a..66a9dbc6 100644 --- a/src/perl.c +++ b/src/perl.c @@ -78,6 +78,8 @@ void boot_DynaLoader (PerlInterpreter *, CV *); static XS (Collectd_plugin_register_ds); static XS (Collectd_plugin_unregister_ds); static XS (Collectd_plugin_dispatch_values); +static XS (Collectd_plugin_flush_one); +static XS (Collectd_plugin_flush_all); static XS (Collectd_plugin_dispatch_notification); static XS (Collectd_plugin_log); static XS (Collectd_call_by_name); @@ -131,6 +133,8 @@ static struct { { "Collectd::plugin_register_data_set", Collectd_plugin_register_ds }, { "Collectd::plugin_unregister_data_set", Collectd_plugin_unregister_ds }, { "Collectd::plugin_dispatch_values", Collectd_plugin_dispatch_values }, + { "Collectd::plugin_flush_one", Collectd_plugin_flush_one }, + { "Collectd::plugin_flush_all", Collectd_plugin_flush_all }, { "Collectd::plugin_dispatch_notification", Collectd_plugin_dispatch_notification }, { "Collectd::plugin_log", Collectd_plugin_log }, @@ -899,6 +903,54 @@ static XS (Collectd_plugin_dispatch_values) } /* static XS (Collectd_plugin_dispatch_values) */ /* + * Collectd::plugin_flush_one (timeout, name). + * + * timeout: + * timeout to use when flushing the data + * + * name: + * name of the plugin to flush + */ +static XS (Collectd_plugin_flush_one) +{ + dXSARGS; + + if (2 != items) { + log_err ("Usage: Collectd::plugin_flush_one(timeout, name)"); + XSRETURN_EMPTY; + } + + log_debug ("Collectd::plugin_flush_one: timeout = %i, name = \"%s\"", + (int)SvIV (ST (0)), SvPV_nolen (ST (1))); + + if (0 == plugin_flush_one ((int)SvIV (ST (0)), SvPV_nolen (ST (1)))) + XSRETURN_YES; + else + XSRETURN_EMPTY; +} /* static XS (Collectd_plugin_flush_one) */ + +/* + * Collectd::plugin_flush_all (timeout). + * + * timeout: + * timeout to use when flushing the data + */ +static XS (Collectd_plugin_flush_all) +{ + dXSARGS; + + if (1 != items) { + log_err ("Usage: Collectd::plugin_flush_all(timeout)"); + XSRETURN_EMPTY; + } + + log_debug ("Collectd::plugin_flush_all: timeout = %i", (int)SvIV (ST (0))); + + plugin_flush_all ((int)SvIV (ST (0))); + XSRETURN_YES; +} /* static XS (Collectd_plugin_flush_all) */ + +/* * Collectd::plugin_dispatch_notification (notif). * * notif: