summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2b9ba6a)
raw | patch | inline | side by side (parent: 2b9ba6a)
author | Paul Sadauskas <psadauskas@gmail.com> | |
Mon, 15 Jun 2009 00:43:50 +0000 (18:43 -0600) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 21 Aug 2009 06:41:53 +0000 (08:41 +0200) |
src/http.c | patch | blob | history |
diff --git a/src/http.c b/src/http.c
index fdcd34fb746dc9c7d47bcdd5807993fc58a88c7a..2cce5803ae1bce27e2b73ef62aa4950302a09425 100644 (file)
--- a/src/http.c
+++ b/src/http.c
}
static int value_list_to_string (char *buffer, int buffer_len,
- const data_set_t *ds, const value_list_t *vl)
+ const data_set_t *ds, const value_list_t *vl, int index)
{
int offset = 0;
int status;
- int i;
gauge_t *rates = NULL;
assert (0 == strcmp (ds->type, vl->type));
memset (buffer, '\0', buffer_len);
- for (i = 0; i < ds->ds_num; i++)
+ if ((ds->ds[index].type != DS_TYPE_COUNTER)
+ && (ds->ds[index].type != DS_TYPE_GAUGE))
+ return (-1);
+
+ if (ds->ds[index].type == DS_TYPE_COUNTER)
{
- if (i > 0)
+ if (rates == NULL)
+ rates = uc_get_rate (ds, vl);
+ if (rates == NULL)
{
- status = ssnprintf (buffer + offset,
- buffer_len - offset,
- ":");
- offset += status;
- }
- if ((ds->ds[i].type != DS_TYPE_COUNTER)
- && (ds->ds[i].type != DS_TYPE_GAUGE))
+ WARNING ("http plugin: "
+ "uc_get_rate failed.");
return (-1);
-
- if (ds->ds[i].type == DS_TYPE_COUNTER)
- {
- if (rates == NULL)
- rates = uc_get_rate (ds, vl);
- if (rates == NULL)
- {
- WARNING ("http plugin: "
- "uc_get_rate failed.");
- return (-1);
- }
- if (isnan(rates[i]))
- {
- /* dont output */
- return (-1);
- }
- status = ssnprintf (buffer + offset,
- buffer_len - offset,
- "%lf", rates[i]);
}
- else /* if (ds->ds[i].type == DS_TYPE_GAUGE) */
- {
- status = ssnprintf (buffer + offset, buffer_len - offset,
- "%lf", vl->values[i].gauge);
- }
-
- if ((status < 1) || (status >= (buffer_len - offset)))
+ if (isnan(rates[index]))
{
- sfree (rates);
+ /* dont output */
return (-1);
}
+ status = ssnprintf (buffer + offset,
+ buffer_len - offset,
+ "%lf", rates[index]);
+ }
+ else /* if (ds->ds[index].type == DS_TYPE_GAUGE) */
+ {
+ status = ssnprintf (buffer + offset, buffer_len - offset,
+ "%lf", vl->values[index].gauge);
+ }
- offset += status;
- } /* for ds->ds_num */
+ if ((status < 1) || (status >= (buffer_len - offset)))
+ {
+ sfree (rates);
+ return (-1);
+ }
+
+ offset += status;
sfree (rates);
return (0);
offset += status;
}
- return (0);
+ return (offset);
} /* int value_list_to_metric_name */
static int http_config (const char *key, const char *value)
user_data_t __attribute__((unused)) *user_data)
{
char metric_name[512];
- char values[512];
+ int metric_prefix_len;
+ char value[512];
char timestamp[512];
- char csv_buffer[1536];
+ char csv_buffer[10240];
int status;
+ int offset = 0;
+ int i;
if (0 != strcmp (ds->type, vl->type)) {
ERROR ("http plugin: DS type does not match value list type");
return -1;
}
- if (value_list_to_metric_name (metric_name, sizeof (metric_name), ds, vl) != 0)
+ metric_prefix_len = value_list_to_metric_name (metric_name,
+ sizeof (metric_name), ds, vl);
+
+ if (metric_prefix_len == -1)
return (-1);
DEBUG ("http plugin: http_write: metric_name = %s;", metric_name);
if (value_list_to_timestamp (timestamp, sizeof (timestamp), ds, vl) != 0)
return (-1);
- if (value_list_to_string (values, sizeof (values), ds, vl) != 0)
- return (-1);
+ for (i = 0; i < ds->ds_num; i++)
+ {
+
+ if (value_list_to_string (value, sizeof (value), ds, vl, i) != 0)
+ return (-1);
+
+ ssnprintf(metric_name + metric_prefix_len, sizeof (metric_name) - metric_prefix_len,
+ ",%s", ds->ds[i].name);
+
+ escape_string (metric_name, sizeof (metric_name));
+
+ status = ssnprintf (csv_buffer + offset, sizeof (csv_buffer) - offset,
+ "\"%s\",%s,%s\n",
+ metric_name, timestamp, value);
+ offset += status;
- escape_string (metric_name, sizeof (metric_name));
+ } /* for */
- status = ssnprintf (csv_buffer, 1536,
- "\"%s\",%s,%s\n",
- metric_name, timestamp, values);
+ printf(csv_buffer);
curl_easy_setopt (curl, CURLOPT_POSTFIELDS, csv_buffer);
status = curl_easy_perform (curl);