/* write_graphite plugin configuation example
*
* <Plugin write_graphite>
- * <Carbon "local-agent">
+ * <Carbon>
* Host "localhost"
* Port 2003
* Prefix "collectd"
#ifndef WG_FORMAT_NAME
#define WG_FORMAT_NAME(ret, ret_len, vl, prefix, name) \
- wg_format_name (ret, ret_len, (vl)->host, (vl)->plugin, (vl)->plugin_instance, \
- (vl)->type, (vl)->type_instance, prefix, name)
+ wg_format_name (ret, ret_len, (vl)->host, (vl)->plugin, \
+ (vl)->plugin_instance, (vl)->type, \
+ (vl)->type_instance, prefix, name)
+#endif
+
+#ifndef WG_SEND_BUF_SIZE
+#define WG_SEND_BUF_SIZE 4096
#endif
/*
*/
struct wg_callback
{
- char *name;
-
int sock_fd;
struct hostent *server;
int port;
char *prefix;
- char send_buf[4096];
+ char send_buf[WG_SEND_BUF_SIZE];
size_t send_buf_free;
size_t send_buf_fill;
cdtime_t send_buf_init_time;
memset (&serv_addr, 0, sizeof (serv_addr));
serv_addr.sin_family = AF_INET;
memcpy (&serv_addr.sin_addr.s_addr,
- cb->server->h_addr,
- cb->server->h_length);
+ cb->server->h_addr,
+ cb->server->h_length);
serv_addr.sin_port = htons(cb->port);
- status = connect(cb->sock_fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
+ status = connect(cb->sock_fd,
+ (struct sockaddr *) &serv_addr,
+ sizeof(serv_addr));
if (status < 0)
{
char errbuf[1024];
wg_flush_nolock (/* timeout = */ 0, cb);
close(cb->sock_fd);
- sfree(cb->name);
sfree(cb->host);
sfree(cb->prefix);
return (0);
}
-static int normalize_hostname (char *dst, const char *src)
+static int mangle_dots (char *dst, const char *src)
{
size_t i;
}
static int wg_format_name (char *ret, int ret_len,
- const char *hostname,
- const char *plugin, const char *plugin_instance,
- const char *type, const char *type_instance,
- const char *prefix, const char *ds_name)
+ const char *hostname,
+ const char *plugin, const char *plugin_instance,
+ const char *type, const char *type_instance,
+ const char *prefix, const char *ds_name)
{
int status;
- char *n_hostname;
+ char *n_hostname = 0;
+ char *n_ds_name = 0;
assert (plugin != NULL);
assert (type != NULL);
return (-1);
}
- if (normalize_hostname(n_hostname, hostname) == -1)
+ if (mangle_dots(n_hostname, hostname) == -1)
{
ERROR ("Unable to normalize hostname");
return (-1);
}
- if ((plugin_instance == NULL) || (strlen (plugin_instance) == 0))
+ if (ds_name && ds_name[0] != '\0') {
+ if (mangle_dots(n_ds_name, ds_name) == -1)
+ {
+ ERROR ("Unable to normalize datasource name");
+ return (-1);
+ }
+ }
+
+ if ((plugin_instance == NULL) || (plugin_instance[0] == '\0'))
{
- if ((type_instance == NULL) || (strlen (type_instance) == 0))
+ if ((type_instance == NULL) || (type_instance[0] == '\0'))
{
- if ((ds_name == NULL) || (strlen (ds_name) == 0))
+ if ((ds_name == NULL) || (ds_name[0] == '\0'))
status = ssnprintf (ret, ret_len, "%s.%s.%s.%s",
prefix, n_hostname, plugin, type);
else
}
else
{
- if ((ds_name == NULL) || (strlen (ds_name) == 0))
+ if ((ds_name == NULL) || (ds_name[0] == '\0'))
status = ssnprintf (ret, ret_len, "%s.%s.%s.%s-%s",
prefix, n_hostname, plugin, type,
type_instance);
}
else
{
- if ((type_instance == NULL) || (strlen (type_instance) == 0))
+ if ((type_instance == NULL) || (type_instance[0] == '\0'))
{
- if ((ds_name == NULL) || (strlen (ds_name) == 0))
+ if ((ds_name == NULL) || (ds_name[0] == '\0'))
status = ssnprintf (ret, ret_len, "%s.%s.%s.%s.%s",
prefix, n_hostname, plugin,
plugin_instance, type);
}
else
{
- if ((ds_name == NULL) || (strlen (ds_name) == 0))
+ if ((ds_name == NULL) || (ds_name[0] == '\0'))
status = ssnprintf (ret, ret_len, "%s.%s.%s.%s.%s-%s",
prefix, n_hostname, plugin,
plugin_instance, type, type_instance);
return (0);
}
-static int wg_send_message (const char* key, const char* value, cdtime_t time, struct wg_callback *cb)
+static int wg_send_message (const char* key, const char* value,
+ cdtime_t time, struct wg_callback *cb)
{
int status;
size_t message_len;
}
static int wg_write_messages (const data_set_t *ds, const value_list_t *vl,
- struct wg_callback *cb)
+ struct wg_callback *cb)
{
char key[10*DATA_MAX_NAME_LEN];
char values[512];
for (i = 0; i < ds->ds_num; i++)
{
/* Copy the identifier to `key' and escape it. */
- status = WG_FORMAT_NAME (key, sizeof (key), vl, cb->prefix, ds->ds[i].name);
+ status = WG_FORMAT_NAME (key, sizeof (key), vl, cb->prefix, \
+ ds->ds[i].name);
if (status != 0)
{
ERROR ("write_graphite plugin: error with format_name");
}
escape_string (key, sizeof (key));
- /* Convert the values to an ASCII representation and put that into
- * `values'. */
+ /* Convert the values to an ASCII representation and put that
+ * into `values'. */
status = wg_format_values (values, sizeof (values), i, ds, vl, 0);
if (status != 0)
{
memset (cb, 0, sizeof (*cb));
cb->sock_fd = -1;
cb->host = NULL;
- cb->name = NULL;
cb->port = 2003;
cb->prefix = NULL;
cb->server = NULL;
pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);
- config_set_string (&cb->name, ci);
- if (cb->name == NULL)
- return (-1);
-
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
else
{
ERROR ("write_graphite plugin: Invalid configuration "
- "option: %s.", child->key);
+ "option: %s.", child->key);
}
}