#define WRITE_HTTP_DEFAULT_BUFFER_SIZE 4096
#endif
+#ifndef WRITE_HTTP_DEFAULT_PREFIX
+#define WRITE_HTTP_DEFAULT_PREFIX "collectd"
+#endif
+
/*
* Private variables
*/
pthread_mutex_t send_lock;
int data_ttl;
+ char *metrics_prefix;
};
typedef struct wh_callback_s wh_callback_t;
{
int status = 0;
+ curl_easy_setopt(cb->curl, CURLOPT_URL, cb->location);
curl_easy_setopt(cb->curl, CURLOPT_POSTFIELDS, data);
status = curl_easy_perform(cb->curl);
curl_easy_setopt(cb->curl, CURLOPT_HTTPHEADER, cb->headers);
curl_easy_setopt(cb->curl, CURLOPT_ERRORBUFFER, cb->curl_errbuf);
- curl_easy_setopt(cb->curl, CURLOPT_URL, cb->location);
curl_easy_setopt(cb->curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(cb->curl, CURLOPT_MAXREDIRS, 50L);
return -1;
}
- ssnprintf(cb->credentials, credentials_size, "%s:%s", cb->user,
- (cb->pass == NULL) ? "" : cb->pass);
+ snprintf(cb->credentials, credentials_size, "%s:%s", cb->user,
+ (cb->pass == NULL) ? "" : cb->pass);
curl_easy_setopt(cb->curl, CURLOPT_USERPWD, cb->credentials);
#endif
curl_easy_setopt(cb->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
int status;
DEBUG("write_http plugin: wh_flush_nolock: timeout = %.3f; "
- "send_buffer_fill = %zu;",
+ "send_buffer_fill = %" PRIsz ";",
CDTIME_T_TO_DOUBLE(timeout), cb->send_buffer_fill);
/* timeout == 0 => flush unconditionally */
sfree(cb->clientcert);
sfree(cb->clientkeypass);
sfree(cb->send_buffer);
+ sfree(cb->metrics_prefix);
sfree(cb);
} /* }}} void wh_callback_free */
return status;
}
- command_len = (size_t)ssnprintf(command, sizeof(command),
- "PUTVAL %s interval=%.3f %s\r\n", key,
- CDTIME_T_TO_DOUBLE(vl->interval), values);
+ command_len = (size_t)snprintf(command, sizeof(command),
+ "PUTVAL %s interval=%.3f %s\r\n", key,
+ CDTIME_T_TO_DOUBLE(vl->interval), values);
if (command_len >= sizeof(command)) {
ERROR("write_http plugin: Command buffer too small: "
- "Need %zu bytes.",
+ "Need %" PRIsz " bytes.",
command_len + 1);
return -1;
}
cb->send_buffer_fill += command_len;
cb->send_buffer_free -= command_len;
- DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%) \"%s\"", cb->location,
- cb->send_buffer_fill, cb->send_buffer_size,
+ DEBUG("write_http plugin: <%s> buffer %" PRIsz "/%" PRIsz " (%g%%) \"%s\"",
+ cb->location, cb->send_buffer_fill, cb->send_buffer_size,
100.0 * ((double)cb->send_buffer_fill) / ((double)cb->send_buffer_size),
command);
return status;
}
- DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%)", cb->location,
- cb->send_buffer_fill, cb->send_buffer_size,
+ DEBUG("write_http plugin: <%s> buffer %" PRIsz "/%" PRIsz " (%g%%)",
+ cb->location, cb->send_buffer_fill, cb->send_buffer_size,
100.0 * ((double)cb->send_buffer_fill) /
((double)cb->send_buffer_size));
status = format_kairosdb_value_list(
cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, ds, vl,
cb->store_rates, (char const *const *)http_attrs, http_attrs_num,
- cb->data_ttl);
+ cb->data_ttl, cb->metrics_prefix);
if (status == -ENOMEM) {
status = wh_flush_nolock(/* timeout = */ 0, cb);
if (status != 0) {
status = format_kairosdb_value_list(
cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, ds, vl,
cb->store_rates, (char const *const *)http_attrs, http_attrs_num,
- cb->data_ttl);
+ cb->data_ttl, cb->metrics_prefix);
}
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
return status;
}
- DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%)", cb->location,
- cb->send_buffer_fill, cb->send_buffer_size,
+ DEBUG("write_http plugin: <%s> buffer %" PRIsz "/%" PRIsz " (%g%%)",
+ cb->location, cb->send_buffer_fill, cb->send_buffer_size,
100.0 * ((double)cb->send_buffer_fill) /
((double)cb->send_buffer_size));
cb->send_metrics = 1;
cb->send_notifications = 0;
cb->data_ttl = 0;
+ cb->metrics_prefix = strdup(WRITE_HTTP_DEFAULT_PREFIX);
+
+ if (cb->metrics_prefix == NULL) {
+ ERROR("write_http plugin: strdup failed.");
+ sfree(cb);
+ return -1;
+ }
pthread_mutex_init(&cb->send_lock, /* attr = */ NULL);
sfree(val);
} else if (strcasecmp("TTL", child->key) == 0) {
status = cf_util_get_int(child, &cb->data_ttl);
+ } else if (strcasecmp("Prefix", child->key) == 0) {
+ status = cf_util_get_string(child, &cb->metrics_prefix);
} else {
ERROR("write_http plugin: Invalid configuration "
"option: %s.",
return -1;
}
+ if (strlen(cb->metrics_prefix) == 0)
+ sfree(cb->metrics_prefix);
+
if (cb->low_speed_limit > 0)
cb->low_speed_time = CDTIME_T_TO_TIME_T(plugin_get_interval());
/* Allocate the buffer. */
cb->send_buffer = malloc(cb->send_buffer_size);
if (cb->send_buffer == NULL) {
- ERROR("write_http plugin: malloc(%zu) failed.", cb->send_buffer_size);
+ ERROR("write_http plugin: malloc(%" PRIsz ") failed.",
+ cb->send_buffer_size);
wh_callback_free(cb);
return -1;
}
/* Nulls the buffer and sets ..._free and ..._fill. */
wh_reset_buffer(cb);
- ssnprintf(callback_name, sizeof(callback_name), "write_http/%s", cb->name);
+ snprintf(callback_name, sizeof(callback_name), "write_http/%s", cb->name);
DEBUG("write_http: Registering write callback '%s' with URL '%s'",
callback_name, cb->location);