summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4eef108)
raw | patch | inline | side by side (parent: 4eef108)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 9 Feb 2009 20:07:31 +0000 (21:07 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 9 Feb 2009 21:23:05 +0000 (22:23 +0100) |
plugin_write() accepts, just like the C counterpart, three arguments,
'plugins', 'datasets' and 'valuelists'. In contrast to the C implementation,
all three arguments may either be a single scalar or a reference to an array -
just like the 'plugins' and 'identifiers' arguments of the Perl implementation
of plugin_flush().
'plugins', 'datasets' and 'valuelists'. In contrast to the C implementation,
all three arguments may either be a single scalar or a reference to an array -
just like the 'plugins' and 'identifiers' arguments of the Perl implementation
of plugin_flush().
bindings/perl/Collectd.pm | patch | blob | history | |
src/collectd-perl.pod | patch | blob | history | |
src/perl.c | patch | blob | history |
index 738206bbbd9f581173befdbab8a8b9413ee00375..6e53b0e70e033bca363cad78a444dbff43ed4a24 100644 (file)
plugin_register
plugin_unregister
plugin_dispatch_values
+ plugin_write
plugin_flush
plugin_flush_one
plugin_flush_all
}
}
+sub plugin_write {
+ my %args = @_;
+
+ my @plugins = ();
+ my @datasets = ();
+ my @valuelists = ();
+
+ if (! defined $args{'valuelists'}) {
+ ERROR ("Collectd::plugin_write: Missing 'valuelists' argument.");
+ return;
+ }
+
+ DEBUG ("Collectd::plugin_write:"
+ . (defined ($args{'plugins'}) ? " plugins = $args{'plugins'}" : "")
+ . (defined ($args{'datasets'}) ? " datasets = $args{'datasets'}" : "")
+ . " valueslists = $args{'valuelists'}");
+
+ if (defined ($args{'plugins'})) {
+ if ("ARRAY" eq ref ($args{'plugins'})) {
+ @plugins = @{$args{'plugins'}};
+ }
+ else {
+ @plugins = ($args{'plugins'});
+ }
+ }
+ else {
+ @plugins = (undef);
+ }
+
+ if ("ARRAY" eq ref ($args{'valuelists'})) {
+ @valuelists = @{$args{'valuelists'}};
+ }
+ else {
+ @valuelists = ($args{'valuelists'});
+ }
+
+ if (defined ($args{'datasets'})) {
+ if ("ARRAY" eq ref ($args{'datasets'})) {
+ @datasets = @{$args{'datasets'}};
+ }
+ else {
+ @datasets = ($args{'datasets'});
+ }
+ }
+ else {
+ @datasets = (undef) x scalar (@valuelists);
+ }
+
+ if ($#datasets != $#valuelists) {
+ ERROR ("Collectd::plugin_write: Invalid number of datasets.");
+ return;
+ }
+
+ foreach my $plugin (@plugins) {
+ for (my $i = 0; $i < scalar (@valuelists); ++$i) {
+ _plugin_write ($plugin, $datasets[$i], $valuelists[$i]);
+ }
+ }
+}
+
sub plugin_flush {
my %args = @_;
diff --git a/src/collectd-perl.pod b/src/collectd-perl.pod
index c3fcb1088319142f44f88c8b5378c050f2973993..18dbafdc8c93cfa9c7cf00f64b62985200b1c71a 100644 (file)
--- a/src/collectd-perl.pod
+++ b/src/collectd-perl.pod
for backwards compatibility but has been deprecated and will be removed in
some future version of collectd.
+=item B<plugin_write> ([B<plugins> => I<...>][, B<datasets> => I<...>],
+B<valuelists> => I<...>)
+
+Calls the write function of the given I<plugins> with the provided I<data
+sets> and I<value lists>. In contrast to B<plugin_dispatch_values>, it does
+not update collectd's internal cache and bypasses the filter mechanism (see
+L<collectd.conf(5)> for details). If the B<plugins> argument has been omitted,
+the values will be dispatched to all registered write plugins. If the
+B<datasets> argument has been omitted, the required data sets are looked up
+according to the C<type> member in the appropriate value list. The value of
+all three arguments may either be a single scalar or a reference to an array.
+If the B<datasets> argument has been specified, the number of data sets has to
+equal the number of specified value lists.
+
=item B<plugin_flush> ([B<timeout> => I<timeout>][, B<plugins> => I<...>][,
B<identifiers> => I<...>])
Flush one or more plugins. I<timeout> and the specified I<identifiers> are
passed on to the registered flush-callbacks. If omitted, the timeout defaults
-to C<-1>. The identifier defaults to the undefined value. If the I<plugins>
+to C<-1>. The identifier defaults to the undefined value. If the B<plugins>
argument has been specified, only named plugins will be flushed. The value of
the B<plugins> and B<identifiers> arguments may either be a string or a
reference to an array of strings.
diff --git a/src/perl.c b/src/perl.c
index 2d4cc867f1d355d59a2aacaa9343ba3aa649adea..9413d2cb8b194676a662fdeb3fa1df8f9cbc690b 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
static XS (Collectd_plugin_register_ds);
static XS (Collectd_plugin_unregister_ds);
static XS (Collectd_plugin_dispatch_values);
+static XS (Collectd__plugin_write);
static XS (Collectd__plugin_flush);
static XS (Collectd_plugin_dispatch_notification);
static XS (Collectd_plugin_log);
{ "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_write", Collectd__plugin_write },
{ "Collectd::_plugin_flush", Collectd__plugin_flush },
{ "Collectd::plugin_dispatch_notification",
Collectd_plugin_dispatch_notification },
return ret;
} /* static int pplugin_dispatch_values (char *, HV *) */
+/*
+ * Submit the values to a single write function.
+ */
+static int pplugin_write (pTHX_ const char *plugin, AV *data_set, HV *values)
+{
+ data_set_t ds;
+ value_list_t vl = VALUE_LIST_INIT;
+
+ int ret;
+
+ if (NULL == values)
+ return -1;
+
+ if (0 != hv2value_list (aTHX_ values, &vl))
+ return -1;
+
+ if ((NULL != data_set)
+ && (0 != av2data_set (aTHX_ data_set, vl.type, &ds)))
+ return -1;
+
+ ret = plugin_write (plugin, NULL == data_set ? NULL : &ds, &vl);
+ if (0 != ret)
+ log_warn ("Dispatching value to plugin \"%s\" failed with status %i.",
+ NULL == plugin ? "<any>" : plugin, ret);
+
+ if (NULL != data_set)
+ sfree (ds.ds);
+ sfree (vl.values);
+ return ret;
+} /* static int pplugin_write (const char *plugin, HV *, HV *) */
+
/*
* Dispatch a notification.
*/
XSRETURN_EMPTY;
} /* static XS (Collectd_plugin_dispatch_values) */
+/* Collectd::plugin_write (plugin, ds, vl).
+ *
+ * plugin:
+ * name of the plugin to call, may be 'undef'
+ *
+ * ds:
+ * data-set that describes the submitted values, may be 'undef'
+ *
+ * vl:
+ * value-list to be written
+ */
+static XS (Collectd__plugin_write)
+{
+ char *plugin;
+ SV *ds, *vl;
+ AV *ds_array;
+
+ int ret;
+
+ dXSARGS;
+
+ if (3 != items) {
+ log_err ("Usage: Collectd::plugin_write(plugin, ds, vl)");
+ XSRETURN_EMPTY;
+ }
+
+ log_debug ("Collectd::plugin_write: plugin=\"%s\", ds=\"%s\", vl=\"%s\"",
+ SvPV_nolen (ST (0)), SvOK (ST (1)) ? SvPV_nolen (ST (1)) : "",
+ SvPV_nolen (ST (2)));
+
+ if (! SvOK (ST (0)))
+ plugin = NULL;
+ else
+ plugin = SvPV_nolen (ST (0));
+
+ ds = ST (1);
+ if (SvROK (ds) && (SVt_PVAV == SvTYPE (SvRV (ds))))
+ ds_array = (AV *)SvRV (ds);
+ else if (! SvOK (ds))
+ ds_array = NULL;
+ else {
+ log_err ("Collectd::plugin_write: Invalid data-set.");
+ XSRETURN_EMPTY;
+ }
+
+ vl = ST (2);
+ if (! (SvROK (vl) && (SVt_PVHV == SvTYPE (SvRV (vl))))) {
+ log_err ("Collectd::plugin_write: Invalid value-list.");
+ XSRETURN_EMPTY;
+ }
+
+ ret = pplugin_write (aTHX_ plugin, ds_array, (HV *)SvRV (vl));
+
+ if (0 == ret)
+ XSRETURN_YES;
+ else
+ XSRETURN_EMPTY;
+} /* static XS (Collectd__plugin_write) */
+
/*
* Collectd::_plugin_flush (plugin, timeout, identifier).
*