summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b9f4405)
raw | patch | inline | side by side (parent: b9f4405)
author | Kevin Bowling <kbowling@llnw.com> | |
Sat, 31 May 2014 02:42:14 +0000 (19:42 -0700) | ||
committer | Marc Fournier <marc.fournier@camptocamp.com> | |
Wed, 13 Aug 2014 12:05:15 +0000 (14:05 +0200) |
src/write_tsdb.c | patch | blob | history |
diff --git a/src/write_tsdb.c b/src/write_tsdb.c
index 2855b3566358cd0980ac697d1bdeb71e9df0e978..8a793b5c2b704825ccaf8434d99ae72cf6fe24fb 100644 (file)
--- a/src/write_tsdb.c
+++ b/src/write_tsdb.c
* <Node>
* Host "localhost"
* Port "4242"
- * Prefix "sys"
* HostTags "status=production deviceclass=www"
* </Node>
* </Plugin>
char *node;
char *service;
- char *prefix;
char *host_tags;
char escape_char;
sfree(cb->node);
sfree(cb->service);
- sfree(cb->prefix);
sfree(cb->host_tags);
pthread_mutex_destroy(&cb->send_lock);
const struct wt_callback *cb,
const char *ds_name)
{
+ int status;
+ char *temp;
char *prefix;
+ const char *meta_prefix = "tsdb_prefix";
- prefix = cb->prefix;
- if (prefix == NULL)
+ status = meta_data_get_string(vl->meta, meta_prefix, &temp);
+ if (status == -ENOENT) {
prefix = "";
+ } else if (status < 0) {
+ sfree(temp);
+ return status;
+ } else {
+ prefix = temp;
+ }
if (ds_name != NULL) {
if (vl->plugin_instance[0] == '\0') {
prefix, vl->plugin, vl->plugin_instance, vl->type_instance);
}
+ sfree(temp);
return 0;
}
static int wt_send_message (const char* key, const char* value,
cdtime_t time, struct wt_callback *cb,
- const char* host)
+ const char* host, meta_data_t *md)
{
int status;
int message_len;
- const char *message_fmt;
+ char *temp, *tags;
char message[1024];
+ const char *message_fmt;
+ const char *meta_tsdb = "tsdb_tags";
/* skip if value is NaN */
if (value[0] == 'n')
return 0;
- message_fmt = "put %s %u %s fqdn=%s %s\r\n";
+ status = meta_data_get_string(md, meta_tsdb, &temp);
+ if (status == -ENOENT) {
+ tags = "";
+ } else if (status < 0) {
+ ERROR("write_tsdb plugin: tags metadata get failure");
+ sfree(temp);
+ pthread_mutex_unlock(&cb->send_lock);
+ return status;
+ } else {
+ tags = temp;
+ }
+
+ message_fmt = "put %s %u %s fqdn=%s %s %s\r\n";
message_len = ssnprintf (message, sizeof(message),
message_fmt,
key,
time),
value,
host,
+ tags,
cb->host_tags);
+
+ sfree(tags);
+
if (message_len >= sizeof(message)) {
ERROR("write_tsdb plugin: message buffer too small: "
"Need %d bytes.", message_len + 1);
}
/* Send the message to tsdb */
- status = wt_send_message(key, values, vl->time, cb, vl->host);
+ status = wt_send_message(key, values, vl->time, cb, vl->host, vl->meta);
if (status != 0)
{
ERROR("write_tsdb plugin: error with "
cb->sock_fd = -1;
cb->node = NULL;
cb->service = NULL;
- cb->prefix = NULL;
cb->host_tags = NULL;
cb->escape_char = WT_DEFAULT_ESCAPE;
cb->store_rates = 1;
cf_util_get_string(child, &cb->node);
else if (strcasecmp("Port", child->key) == 0)
cf_util_get_service(child, &cb->service);
- else if (strcasecmp("Prefix", child->key) == 0)
- cf_util_get_string(child, &cb->prefix);
else if (strcasecmp("HostTags", child->key) == 0)
cf_util_get_string(child, &cb->host_tags);
else if (strcasecmp("StoreRates", child->key) == 0)