* Based on the write_http plugin.
**/
-/* write_graphite plugin configuation example
+/* write_graphite plugin configuration example
*
* <Plugin write_graphite>
* <Carbon>
* Protocol "udp"
* LogSendErrors true
* Prefix "collectd"
+ * UseTags true
+ * ReverseHost false
* </Carbon>
* </Plugin>
*/
#include "collectd.h"
-#include "common.h"
#include "plugin.h"
+#include "utils/common/common.h"
+#include "utils/format_graphite/format_graphite.h"
#include "utils_complain.h"
-#include "utils_format_graphite.h"
#include <netdb.h>
#endif
#ifndef WG_DEFAULT_LOG_SEND_ERRORS
-#define WG_DEFAULT_LOG_SEND_ERRORS 1
+#define WG_DEFAULT_LOG_SEND_ERRORS true
#endif
#ifndef WG_DEFAULT_ESCAPE
char *node;
char *service;
char *protocol;
- _Bool log_send_errors;
+ bool log_send_errors;
char *prefix;
char *postfix;
char escape_char;
/* Force reconnect useful for load balanced environments */
cdtime_t last_reconnect_time;
cdtime_t reconnect_interval;
- _Bool reconnect_interval_reached;
+ bool reconnect_interval_reached;
};
/* wg_force_reconnect_check closes cb->sock_fd when it was open for longer
close(cb->sock_fd);
cb->sock_fd = -1;
cb->last_reconnect_time = now;
- cb->reconnect_interval_reached = 1;
+ cb->reconnect_interval_reached = true;
INFO("write_graphite plugin: Connection closed after %.3f seconds.",
CDTIME_T_TO_DOUBLE(now - cb->last_reconnect_time));
status = swrite(cb->sock_fd, cb->send_buf, strlen(cb->send_buf));
if (status != 0) {
if (cb->log_send_errors) {
- char errbuf[1024];
ERROR("write_graphite plugin: send to %s:%s (%s) failed with status %zi "
"(%s)",
- cb->node, cb->service, cb->protocol, status,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ cb->node, cb->service, cb->protocol, status, STRERRNO);
}
close(cb->sock_fd);
int status;
DEBUG("write_graphite plugin: wg_flush_nolock: timeout = %.3f; "
- "send_buf_fill = %zu;",
+ "send_buf_fill = %" PRIsz ";",
(double)timeout, cb->send_buf_fill);
/* timeout == 0 => flush unconditionally */
cb->sock_fd =
socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (cb->sock_fd < 0) {
- char errbuf[1024];
- snprintf(connerr, sizeof(connerr), "failed to open socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ snprintf(connerr, sizeof(connerr), "failed to open socket: %s", STRERRNO);
continue;
}
status = connect(cb->sock_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- snprintf(connerr, sizeof(connerr), "failed to connect to remote "
- "host: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ snprintf(connerr, sizeof(connerr), "failed to connect to remote host: %s",
+ STRERRNO);
close(cb->sock_fd);
cb->sock_fd = -1;
continue;
freeaddrinfo(ai_list);
if (cb->sock_fd < 0) {
- if (connerr[0] == '\0')
- /* this should not happen but try to get a message anyway */
- sstrerror(errno, connerr, sizeof(connerr));
c_complain(LOG_ERR, &cb->init_complaint,
"write_graphite plugin: Connecting to %s:%s via %s failed. "
"The last error was: %s",
if (!cb->reconnect_interval_reached || (cb->send_buf_free == 0))
wg_reset_buffer(cb);
else
- cb->reconnect_interval_reached = 0;
+ cb->reconnect_interval_reached = false;
return 0;
}
cb->send_buf_fill += message_len;
cb->send_buf_free -= message_len;
- DEBUG("write_graphite plugin: [%s]:%s (%s) buf %zu/%zu (%.1f %%) \"%s\"",
+ DEBUG("write_graphite plugin: [%s]:%s (%s) buf %" PRIsz "/%" PRIsz
+ " (%.1f %%) \"%s\"",
cb->node, cb->service, cb->protocol, cb->send_buf_fill,
sizeof(cb->send_buf),
100.0 * ((double)cb->send_buf_fill) / ((double)sizeof(cb->send_buf)),
cb->protocol = strdup(WG_DEFAULT_PROTOCOL);
cb->last_reconnect_time = cdtime();
cb->reconnect_interval = 0;
- cb->reconnect_interval_reached = 0;
+ cb->reconnect_interval_reached = false;
cb->log_send_errors = WG_DEFAULT_LOG_SEND_ERRORS;
cb->prefix = NULL;
cb->postfix = NULL;
cf_util_get_flag(child, &cb->format_flags, GRAPHITE_PRESERVE_SEPARATOR);
else if (strcasecmp("DropDuplicateFields", child->key) == 0)
cf_util_get_flag(child, &cb->format_flags, GRAPHITE_DROP_DUPE_FIELDS);
+ else if (strcasecmp("UseTags", child->key) == 0)
+ cf_util_get_flag(child, &cb->format_flags, GRAPHITE_USE_TAGS);
+ else if (strcasecmp("ReverseHost", child->key) == 0)
+ cf_util_get_flag(child, &cb->format_flags, GRAPHITE_REVERSE_HOST);
else if (strcasecmp("EscapeCharacter", child->key) == 0)
config_set_char(&cb->escape_char, child);
else {
plugin_register_write(callback_name, wg_write,
&(user_data_t){
- .data = cb, .free_func = wg_callback_free,
+ .data = cb,
+ .free_func = wg_callback_free,
});
plugin_register_flush(callback_name, wg_flush, &(user_data_t){.data = cb});