src/collectd.h: Define GAUGE_FORMAT.
authorFlorian Forster <octo@collectd.org>
Fri, 22 May 2015 09:11:27 +0000 (11:11 +0200)
committerFlorian Forster <octo@collectd.org>
Fri, 22 May 2015 09:11:34 +0000 (11:11 +0200)
This format is also used in format_values(), so exported gauges follow a common
format.

See also issue #1039

src/collectd.h
src/common.c
src/utils_format_json.h

index 7cb405c..1b1bc49 100644 (file)
@@ -287,6 +287,10 @@ typedef int _Bool;
 # endif
 #endif
 
+#ifndef GAUGE_FORMAT
+# define GAUGE_FORMAT "%.15g"
+#endif
+
 /* Type for time as used by "utils_time.h" */
 typedef uint64_t cdtime_t;
 
index 8a40792..efd63c0 100644 (file)
@@ -902,18 +902,17 @@ int format_values (char *ret, size_t ret_len, /* {{{ */
         for (i = 0; i < ds->ds_num; i++)
         {
                 if (ds->ds[i].type == DS_TYPE_GAUGE)
-                        BUFFER_ADD (":%f", vl->values[i].gauge);
+                        BUFFER_ADD (":"GAUGE_FORMAT, vl->values[i].gauge);
                 else if (store_rates)
                 {
                         if (rates == NULL)
                                 rates = uc_get_rate (ds, vl);
                         if (rates == NULL)
                         {
-                                WARNING ("format_values: "
-                                               "uc_get_rate failed.");
+                                WARNING ("format_values: uc_get_rate failed.");
                                 return (-1);
                         }
-                        BUFFER_ADD (":%g", rates[i]);
+                        BUFFER_ADD (":"GAUGE_FORMAT, rates[i]);
                 }
                 else if (ds->ds[i].type == DS_TYPE_COUNTER)
                         BUFFER_ADD (":%llu", vl->values[i].counter);
@@ -923,7 +922,7 @@ int format_values (char *ret, size_t ret_len, /* {{{ */
                         BUFFER_ADD (":%"PRIu64, vl->values[i].absolute);
                 else
                 {
-                        ERROR ("format_values plugin: Unknown data source type: %i",
+                        ERROR ("format_values: Unknown data source type: %i",
                                         ds->ds[i].type);
                         sfree (rates);
                         return (-1);
index f8f5a35..7a4aa54 100644 (file)
@@ -26,7 +26,7 @@
 #include "plugin.h"
 
 #ifndef JSON_GAUGE_FORMAT
-# define JSON_GAUGE_FORMAT "%.15g"
+# define JSON_GAUGE_FORMAT GAUGE_FORMAT
 #endif
 
 int format_json_initialize (char *buffer,