From: Florian Forster Date: Wed, 24 Mar 2010 16:38:58 +0000 (+0100) Subject: src/utils_format_json.c: Convert all data source types to rates except GAUGE. X-Git-Tag: collectd-4.10.0~46 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a1197a4742bc20a68e1ded8feaa85d710c28ddba;p=collectd.git 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. --- 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 */