From a1197a4742bc20a68e1ded8feaa85d710c28ddba Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 24 Mar 2010 17:38:58 +0100 Subject: [PATCH] src/utils_format_json.c: Convert all data source types to rates except GAUGE. This is basically the same fix as previously done for the write_http plugin. --- src/utils_format_json.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/utils_format_json.c b/src/utils_format_json.c index e8fcb35b..69e0cd42 100644 --- a/src/utils_format_json.c +++ b/src/utils_format_json.c @@ -112,27 +112,24 @@ static int values_to_json (char *buffer, size_t buffer_size, /* {{{ */ else BUFFER_ADD ("null"); } - else if (ds->ds[i].type == DS_TYPE_COUNTER) + else if (store_rates) { - if (store_rates != 0) + if (rates == NULL) + rates = uc_get_rate (ds, vl); + if (rates == NULL) { - if (rates == NULL) - rates = uc_get_rate (ds, vl); - if (rates == NULL) - { - WARNING ("utils_format_json: " - "uc_get_rate failed."); - sfree(rates); - return (-1); - } - if(isfinite (rates[i])) - BUFFER_ADD ("%g", rates[i]); - else - BUFFER_ADD ("null"); + WARNING ("utils_format_json: uc_get_rate failed."); + sfree(rates); + return (-1); } + + if(isfinite (rates[i])) + BUFFER_ADD ("%g", rates[i]); else - BUFFER_ADD ("%llu", vl->values[i].counter); + BUFFER_ADD ("null"); } + else if (ds->ds[i].type == DS_TYPE_COUNTER) + BUFFER_ADD ("%llu", vl->values[i].counter); else if (ds->ds[i].type == DS_TYPE_DERIVE) BUFFER_ADD ("%"PRIi64, vl->values[i].derive); else if (ds->ds[i].type == DS_TYPE_ABSOLUTE) @@ -141,6 +138,7 @@ static int values_to_json (char *buffer, size_t buffer_size, /* {{{ */ { ERROR ("format_json: Unknown data source type: %i", ds->ds[i].type); + sfree (rates); return (-1); } } /* for ds->ds_num */ -- 2.30.2