summaryrefslogtreecommitdiffstats
path: root/src/plugins/influxdb-writer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/influxdb-writer.c')
-rw-r--r--src/plugins/influxdb-writer.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c
index 9090a32..2815b19 100644
--- a/src/plugins/influxdb-writer.c
+++ b/src/plugins/influxdb-writer.c
@@ -50,37 +50,35 @@ void influxdb_write_curl_cb(void *closure, int status, CURL *curl, const char *r
}
}
+
+static void serialize_list_to_query(char *query, struct list *node) {
+ bool first = true;
+
+ while(node != NULL) {
+ if(first) {
+ concatenate(query, node->key, " ");
+ first = false;
+ } else {
+ concatenate(query, node->key, ",");
+ }
+
+ if(json_object_is_type(node->value, json_type_string))
+ concatenate(query, json_object_get_string(node->value), "=");
+ else
+ concatenate(query, json_object_to_json_string(node->value), "=");
+ node = node->next;
+ }
+}
+
+
static size_t format_write_args(char *query, struct series_t *serie)
{
char *ts;
- struct list *tags = serie->serie_columns.tags;
- struct list *fields = serie->serie_columns.fields;
strncat(query, serie->name, strlen(serie->name));
- if(tags) {
- while(tags != NULL) {
- concatenate(query, tags->key, ",");
- if(json_object_is_type(tags->value, json_type_string))
- concatenate(query, json_object_get_string(tags->value), "=");
- else
- concatenate(query, json_object_to_json_string(tags->value), "=");
- tags = tags->next;
- }
- }
- if(fields) {
- int i = 0;
- for(struct list *it = fields; it != NULL; it = it->next) {
- if(!i)
- concatenate(query, fields->key, " ");
- else
- concatenate(query, fields->key, ",");
- if(json_object_is_type(fields->value, json_type_string))
- concatenate(query, json_object_get_string(fields->value), "=");
- else
- concatenate(query, json_object_to_json_string(fields->value), "=");
- i++;
- }
- }
+
+ serialize_list_to_query(query, serie->serie_columns.tags);
+ serialize_list_to_query(query, serie->serie_columns.fields);
asprintf(&ts, "%lu", serie->timestamp);
concatenate(query, ts, " ");