#define WRITE_HTTP_DEFAULT_BUFFER_SIZE 4096
#endif
+#ifndef WRITE_HTTP_DEFAULT_PREFIX
+#define WRITE_HTTP_DEFAULT_PREFIX "collectd"
+#endif
+
/*
* Private variables
*/
char *user;
char *pass;
char *credentials;
- _Bool verify_peer;
- _Bool verify_host;
+ bool verify_peer;
+ bool verify_host;
char *cacert;
char *capath;
char *clientkey;
char *clientcert;
char *clientkeypass;
long sslversion;
- _Bool store_rates;
- _Bool log_http_error;
+ bool store_rates;
+ bool log_http_error;
int low_speed_limit;
time_t low_speed_time;
int timeout;
#define WH_FORMAT_JSON 1
#define WH_FORMAT_KAIROSDB 2
int format;
- _Bool send_metrics;
- _Bool send_notifications;
+ bool send_metrics;
+ bool send_notifications;
CURL *curl;
struct curl_slist *headers;
pthread_mutex_t send_lock;
int data_ttl;
+ char *metrics_prefix;
};
typedef struct wh_callback_s wh_callback_t;
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 */
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));
ERROR("write_http plugin: calloc failed.");
return -1;
}
- cb->verify_peer = 1;
- cb->verify_host = 1;
+ cb->verify_peer = true;
+ cb->verify_host = true;
cb->format = WH_FORMAT_COMMAND;
cb->sslversion = CURL_SSLVERSION_DEFAULT;
cb->low_speed_limit = 0;
cb->timeout = 0;
- cb->log_http_error = 0;
+ cb->log_http_error = false;
cb->headers = NULL;
- cb->send_metrics = 1;
- cb->send_notifications = 0;
+ cb->send_metrics = true;
+ cb->send_notifications = false;
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;
}