summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 359b83c)
raw | patch | inline | side by side (parent: 359b83c)
author | Alex Petrov <oleksandr.petrov@gmail.com> | |
Wed, 17 Dec 2014 11:43:24 +0000 (12:43 +0100) | ||
committer | Alex Petrov <oleksandr.petrov@gmail.com> | |
Wed, 17 Dec 2014 11:43:24 +0000 (12:43 +0100) |
Currently, "plugin_dispatch_multivalue" works only with
"gauge_t" metric type. This commit changes it to accept a
"store_type" (one of "DS_TYPE_{GAUGE|COUTNTER|ABSOLUTE|DERIVE}").
"gauge_t" metric type. This commit changes it to accept a
"store_type" (one of "DS_TYPE_{GAUGE|COUTNTER|ABSOLUTE|DERIVE}").
src/daemon/plugin.c | patch | blob | history | |
src/daemon/plugin.h | patch | blob | history | |
src/memory.c | patch | blob | history | |
src/swap.c | patch | blob | history |
diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c
index 6c6ab63c0209891470c824d1f8dc432af4695f5b..3a95f362a319e176c3ce87ced0fce37216964794 100644 (file)
--- a/src/daemon/plugin.c
+++ b/src/daemon/plugin.c
__attribute__((sentinel))
int plugin_dispatch_multivalue (value_list_t const *template, /* {{{ */
- _Bool store_percentage, ...)
+ _Bool store_percentage, int store_type, ...)
{
value_list_t *vl;
int failed = 0;
assert (template->values_len == 1);
- va_start (ap, store_percentage);
- while (42)
- {
- char const *name;
- gauge_t value;
+ /* Calculate sum for Gauge to calculate percent if needed */
+ if (DS_TYPE_GAUGE == store_type) {
+ va_start (ap, store_type);
+ while (42)
+ {
+ char const *name;
+ gauge_t value;
- name = va_arg (ap, char const *);
- if (name == NULL)
- break;
+ name = va_arg (ap, char const *);
+ if (name == NULL)
+ break;
- value = va_arg (ap, gauge_t);
- if (!isnan (value))
- sum += value;
+ value = va_arg (ap, gauge_t);
+ if (!isnan (value))
+ sum += value;
+ }
+ va_end (ap);
}
- 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);
+ va_start (ap, store_type);
while (42)
{
char const *name;
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;
+ switch (store_type)
+ {
+ case DS_TYPE_GAUGE:
+ vl->values[0].gauge = va_arg (ap, gauge_t);
+ if (store_percentage)
+ vl->values[0].gauge *= 100.0 / sum;
+ break;
+ case DS_TYPE_ABSOLUTE:
+ vl->values[0].absolute = va_arg (ap, absolute_t);
+ break;
+ case DS_TYPE_COUNTER:
+ vl->values[0].counter = va_arg (ap, counter_t);
+ break;
+ case DS_TYPE_DERIVE:
+ vl->values[0].derive = va_arg (ap, derive_t);
+ break;
+ default:
+ ERROR ("plugin_dispatch_multivalue: given store_type is incorrect.");
+ failed++;
+ }
+
status = plugin_write_enqueue (vl);
if (status != 0)
diff --git a/src/daemon/plugin.h b/src/daemon/plugin.h
index d773e09478b818a09dd898c110dfb923532f87ac..86a2d6625acaa7937fd44f7eb3f453bcfc2f9df8 100644 (file)
--- a/src/daemon/plugin.h
+++ b/src/daemon/plugin.h
* plugin_dispatch_multivalue
*
* SYNOPSIS
- * plugin_dispatch_multivalue (vl, 1,
+ * plugin_dispatch_multivalue (vl, 1, DS_TYPE_GAUGE,
* "free", 42.0,
* "used", 58.0,
* NULL);
* 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
+ * The variadic arguments is a list of type_instance / type pairs, that are
+ * interpreted as type "char const *" and type, encoded by their corresponding
+ * "store_type":
+ *
+ * - "gauge_t" when "DS_TYPE_GAUGE"
+ * - "absolute_t" when "DS_TYPE_ABSOLUTE"
+ * - "derive_t" when "DS_TYPE_DERIVE"
+ * - "counter_t" when "DS_TYPE_COUNTER"
+ *
+ * The last argument must be
* a NULL pointer to signal end-of-list.
*
* RETURNS
*/
__attribute__((sentinel))
int plugin_dispatch_multivalue (value_list_t const *vl,
- _Bool store_percentage, ...);
+ _Bool store_percentage, int store_type, ...);
int plugin_dispatch_missing (const value_list_t *vl);
diff --git a/src/memory.c b/src/memory.c
index 7e7fd8e5290ac4ebe1cfdb93ead5af574356e3f2..fb2f3d38a4045fd8790160a1155ed04cda33ab23 100644 (file)
--- a/src/memory.c
+++ b/src/memory.c
#define MEMORY_SUBMIT(...) do { \
if (values_absolute) \
- plugin_dispatch_multivalue (vl, 0, __VA_ARGS__, NULL); \
+ plugin_dispatch_multivalue (vl, 0, DS_TYPE_GAUGE, __VA_ARGS__, NULL); \
if (values_percentage) \
- plugin_dispatch_multivalue (vl, 1, __VA_ARGS__, NULL); \
+ plugin_dispatch_multivalue (vl, 1, DS_TYPE_GAUGE, __VA_ARGS__, NULL); \
} while (0)
static int memory_read_internal (value_list_t *vl)
diff --git a/src/swap.c b/src/swap.c
index 0642afac78d82792318f40a57696cfe862d13ed2..8af18f4bf6c0ddd76008c912675c60391b1f1b9b 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
sstrncpy (vl.type, "swap", sizeof (vl.type));
if (values_absolute)
- plugin_dispatch_multivalue (&vl, 0,
+ plugin_dispatch_multivalue (&vl, 0, DS_TYPE_GAUGE,
"used", used, "free", free,
other_name, other_value, NULL);
if (values_percentage)
- plugin_dispatch_multivalue (&vl, 1,
+ plugin_dispatch_multivalue (&vl, 1, DS_TYPE_GAUGE,
"used", used, "free", free,
other_name, other_value, NULL);
} /* }}} void swap_submit_usage */