summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ef74a29)
raw | patch | inline | side by side (parent: ef74a29)
author | Florian Forster <octo@collectd.org> | |
Mon, 13 Jan 2014 14:57:34 +0000 (15:57 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 13 Jan 2014 14:57:34 +0000 (15:57 +0100) |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index 6c7aa057cf2d272b126eadf6308a76188d3f3b1a..5f1ca559f4ffb30393e4f7a5ec1bff0424c71025 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
/**
* collectd - src/plugin.c
- * Copyright (C) 2005-2013 Florian octo Forster
+ * Copyright (C) 2005-2014 Florian octo Forster
*
* 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
return (0);
}
+__attribute__((sentinel))
+int plugin_dispatch_multivalue (value_list_t const *template, /* {{{ */
+ _Bool store_percentage, ...)
+{
+ value_list_t *vl;
+ int failed = 0;
+ gauge_t sum = 0.0;
+ va_list ap;
+
+ assert (template->values_len == 1);
+
+ va_start (ap, store_percentage);
+ while (42)
+ {
+ char const *name;
+ gauge_t value;
+
+ name = va_arg (ap, char const *);
+ if (name == NULL)
+ break;
+
+ value = va_arg (ap, gauge_t);
+ if (!isnan (value))
+ sum += value;
+ }
+ va_end (ap);
+
+ vl = plugin_value_list_clone (template);
+ /* plugin_value_list_clone makes sure vl->time is set to non-zero. */
+ if (store_percentage)
+ sstrncpy (vl->type, "percent", sizeof (vl->type));
+
+ va_start (ap, store_percentage);
+ while (42)
+ {
+ char const *name;
+ int status;
+
+ /* Set the type instance. */
+ name = va_arg (ap, char const *);
+ if (name == NULL)
+ break;
+ sstrncpy (vl->type_instance, name, sizeof (vl->type_instance));
+
+ /* Set the value. */
+ vl->values[0].gauge = va_arg (ap, gauge_t);
+ if (store_percentage)
+ vl->values[0].gauge *= 100.0 / sum;
+
+ status = plugin_write_enqueue (vl);
+ if (status != 0)
+ failed++;
+ }
+ va_end (ap);
+
+ plugin_value_list_free (vl);
+ return (failed);
+} /* }}} int plugin_dispatch_multivalue */
+
int plugin_dispatch_notification (const notification_t *notif)
{
llentry_t *le;
diff --git a/src/plugin.h b/src/plugin.h
index 8f0c6d86105fbfe56547d6b5d78ac9fd7a7f4b26..924c842d28de940b5522dfb200a440e1ac7f585d 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
#define PLUGIN_H
/**
* collectd - src/plugin.h
- * Copyright (C) 2005-2011 Florian octo Forster
+ * Copyright (C) 2005-2014 Florian octo Forster
*
* 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
* function.
*/
int plugin_dispatch_values (value_list_t const *vl);
+
+/*
+ * NAME
+ * plugin_dispatch_multivalue
+ *
+ * SYNOPSIS
+ * plugin_dispatch_multivalue (vl, 1,
+ * "free", 42.0,
+ * "used", 58.0,
+ * NULL);
+ *
+ * DESCRIPTION
+ * Takes a list of type instances and values and dispatches that in a batch,
+ * making sure that all values have the same time stamp. If "store_percentage"
+ * is set to true, the "type" is set to "percent" and a percentage is
+ * calculated and dispatched, rather than the absolute values. Values that are
+ * NaN are dispatched as NaN and will not influence the total.
+ *
+ * The variadic arguments is a list of type_instance / gauge pairs, that are
+ * interpreted as type "char const *" and "gauge_t". The last argument must be
+ * a NULL pointer to signal end-of-list.
+ *
+ * RETURNS
+ * The number of values it failed to dispatch (zero on success).
+ */
+__attribute__((sentinel))
+int plugin_dispatch_multivalue (value_list_t const *vl,
+ _Bool store_percentage, ...);
+
int plugin_dispatch_missing (const value_list_t *vl);
int plugin_dispatch_notification (const notification_t *notif);