[collectd] [PATCH] perl plugin: Exported plugin_flush*() to Perl.
Sebastian Harl
sh at tokkee.org
Sun Apr 27 20:56:09 CEST 2008
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 <sh at tokkee.org>
---
bindings/perl/Collectd.pm | 31 ++++++++++++++++++++++++++
src/perl.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/bindings/perl/Collectd.pm b/bindings/perl/Collectd.pm
index 399fca8..ee265e8 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 beea288..66a9dbc 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:
--
1.5.5.1.79.g57cf
-------------- 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/20080427/d3e90c86/attachment.pgp
More information about the collectd
mailing list