summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cdf943c)
raw | patch | inline | side by side (parent: cdf943c)
author | Chris Buben <cbuben@eventlogic.com> | |
Wed, 24 Mar 2010 03:53:30 +0000 (20:53 -0700) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Wed, 24 Mar 2010 16:33:50 +0000 (17:33 +0100) |
StoreRates for write_http was inconsistent in that it only functioned
for WH_FORMAT_COMMAND. Extend StoreRates so that it works when using
WH_FORMAT_JSON, too.
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
for WH_FORMAT_COMMAND. Extend StoreRates so that it works when using
WH_FORMAT_JSON, too.
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/utils_format_json.c | patch | blob | history | |
src/utils_format_json.h | patch | blob | history | |
src/write_http.c | patch | blob | history |
index 75a73aeea4a00e0465f27e8fa09134ca04bea921..e8fcb35baac06cd6694f4926e18d391758b09876 100644 (file)
--- a/src/utils_format_json.c
+++ b/src/utils_format_json.c
#include "plugin.h"
#include "common.h"
+#include "utils_cache.h"
#include "utils_format_json.h"
static int escape_string (char *buffer, size_t buffer_size, /* {{{ */
} /* }}} int buffer_add_string */
static int values_to_json (char *buffer, size_t buffer_size, /* {{{ */
- const data_set_t *ds, const value_list_t *vl)
+ const data_set_t *ds, const value_list_t *vl, int store_rates)
{
size_t offset = 0;
int i;
+ gauge_t *rates = NULL;
memset (buffer, 0, buffer_size);
status = ssnprintf (buffer + offset, buffer_size - offset, \
__VA_ARGS__); \
if (status < 1) \
+ { \
+ sfree(rates); \
return (-1); \
+ } \
else if (((size_t) status) >= (buffer_size - offset)) \
+ { \
+ sfree(rates); \
return (-ENOMEM); \
+ } \
else \
- offset += ((size_t) status); \
+ offset += ((size_t) status); \
} while (0)
BUFFER_ADD ("[");
BUFFER_ADD ("null");
}
else if (ds->ds[i].type == DS_TYPE_COUNTER)
- BUFFER_ADD ("%llu", vl->values[i].counter);
+ {
+ if (store_rates != 0)
+ {
+ 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");
+ }
+ else
+ 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)
#undef BUFFER_ADD
DEBUG ("format_json: values_to_json: buffer = %s;", buffer);
-
+ sfree(rates);
return (0);
} /* }}} int values_to_json */
static int value_list_to_json (char *buffer, size_t buffer_size, /* {{{ */
- const data_set_t *ds, const value_list_t *vl)
+ const data_set_t *ds, const value_list_t *vl, int store_rates)
{
char temp[512];
size_t offset = 0;
* a square bracket in `format_json_finalize'. */
BUFFER_ADD (",{");
- status = values_to_json (temp, sizeof (temp), ds, vl);
+ status = values_to_json (temp, sizeof (temp), ds, vl, store_rates);
if (status != 0)
return (status);
BUFFER_ADD ("\"values\":%s", temp);
static int format_json_value_list_nocheck (char *buffer, /* {{{ */
size_t *ret_buffer_fill, size_t *ret_buffer_free,
const data_set_t *ds, const value_list_t *vl,
- size_t temp_size)
+ int store_rates, size_t temp_size)
{
char temp[temp_size];
int status;
- status = value_list_to_json (temp, sizeof (temp), ds, vl);
+ status = value_list_to_json (temp, sizeof (temp), ds, vl, store_rates);
if (status != 0)
return (status);
temp_size = strlen (temp);
int format_json_value_list (char *buffer, /* {{{ */
size_t *ret_buffer_fill, size_t *ret_buffer_free,
- const data_set_t *ds, const value_list_t *vl)
+ const data_set_t *ds, const value_list_t *vl, int store_rates)
{
if ((buffer == NULL)
|| (ret_buffer_fill == NULL) || (ret_buffer_free == NULL)
return (format_json_value_list_nocheck (buffer,
ret_buffer_fill, ret_buffer_free, ds, vl,
- (*ret_buffer_free) - 2));
+ store_rates, (*ret_buffer_free) - 2));
} /* }}} int format_json_value_list */
/* vim: set sw=2 sts=2 et fdm=marker : */
index 880a79dc85a9482cbb80b20f674bdd6f5b528e04..c902e27220f2b542baa5cb43b19b24dc4291bec8 100644 (file)
--- a/src/utils_format_json.h
+++ b/src/utils_format_json.h
size_t *ret_buffer_fill, size_t *ret_buffer_free);
int format_json_value_list (char *buffer,
size_t *ret_buffer_fill, size_t *ret_buffer_free,
- const data_set_t *ds, const value_list_t *vl);
+ const data_set_t *ds, const value_list_t *vl, int store_rates);
int format_json_finalize (char *buffer,
size_t *ret_buffer_fill, size_t *ret_buffer_free);
diff --git a/src/write_http.c b/src/write_http.c
index cc47b16ad731c7fa48accf0d984acd566518fe44..ab8757ed67f151875bc806279425f3c86d971c87 100644 (file)
--- a/src/write_http.c
+++ b/src/write_http.c
@@ -446,7 +446,7 @@ static int wh_write_json (const data_set_t *ds, const value_list_t *vl, /* {{{ *
status = format_json_value_list (cb->send_buffer,
&cb->send_buffer_fill,
&cb->send_buffer_free,
- ds, vl);
+ ds, vl, cb->store_rates);
if (status == (-ENOMEM))
{
status = wh_flush_nolock (/* timeout = */ -1, cb);
@@ -460,7 +460,7 @@ static int wh_write_json (const data_set_t *ds, const value_list_t *vl, /* {{{ *
status = format_json_value_list (cb->send_buffer,
&cb->send_buffer_fill,
&cb->send_buffer_free,
- ds, vl);
+ ds, vl, cb->store_rates);
}
if (status != 0)
{