X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_graphite.c;h=3ff8e04d991396df22fa0b91239d2b9c45d758e3;hb=3e1b18d9e950553989dfde85cac475c5da7ae34c;hp=b7924ba8c2d0166bfa8ead827f544eefd2005929;hpb=a49ed2ad7f046517f1e48b417a71ac2005362d2f;p=collectd.git diff --git a/src/write_graphite.c b/src/write_graphite.c index b7924ba8..3ff8e04d 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -449,7 +449,6 @@ static int wg_send_message (const char* key, const char* value, return (-1); } - pthread_mutex_lock (&cb->send_lock); if (cb->sock_fd < 0) @@ -472,6 +471,8 @@ static int wg_send_message (const char* key, const char* value, return (status); } } + + /* Assert that we have enough space for this message. */ assert (message_len < cb->send_buf_free); /* `message_len + 1' because `message_len' does not include the @@ -481,14 +482,13 @@ static int wg_send_message (const char* key, const char* value, cb->send_buf_fill += message_len; cb->send_buf_free -= message_len; - DEBUG ("write_graphite plugin: <%s:%s> buf %zu/%zu (%g%%) \"%s\"", + DEBUG ("write_graphite plugin: [%s]:%s buf %zu/%zu (%.1f %%) \"%s\"", cb->node, cb->service, cb->send_buf_fill, sizeof (cb->send_buf), 100.0 * ((double) cb->send_buf_fill) / ((double) sizeof (cb->send_buf)), message); - /* Check if we have enough space for this message. */ pthread_mutex_unlock (&cb->send_lock); return (0); @@ -509,45 +509,15 @@ static int wg_write_messages (const data_set_t *ds, const value_list_t *vl, return -1; } - if (ds->ds_num > 1) - { - 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, ds->ds[i].name); - if (status != 0) - { - ERROR ("write_graphite plugin: error with format_name"); - return (status); - } - - escape_string (key, sizeof (key)); - /* Convert the values to an ASCII representation and put that - * into `values'. */ - status = wg_format_values (values, sizeof (values), i, ds, vl, - cb->store_rates); - if (status != 0) - { - ERROR ("write_graphite plugin: error with " - "wg_format_values"); - return (status); - } - - /* Send the message to graphite */ - status = wg_send_message (key, values, vl->time, cb); - if (status != 0) - { - ERROR ("write_graphite plugin: error with " - "wg_send_message"); - return (status); - } - } - } - else + for (i = 0; i < ds->ds_num; i++) { + const char *ds_name = NULL; + + if (cb->always_append_ds || (ds->ds_num > 1)) + ds_name = ds->ds[i].name; + /* Copy the identifier to `key' and escape it. */ - status = wg_format_name (key, sizeof (key), vl, cb, - cb->always_append_ds ? ds->ds[0].name : NULL); + status = wg_format_name (key, sizeof (key), vl, cb, ds_name); if (status != 0) { ERROR ("write_graphite plugin: error with format_name"); @@ -557,7 +527,7 @@ static int wg_write_messages (const data_set_t *ds, const value_list_t *vl, escape_string (key, sizeof (key)); /* Convert the values to an ASCII representation and put that into * `values'. */ - status = wg_format_values (values, sizeof (values), 0, ds, vl, + status = wg_format_values (values, sizeof (values), i, ds, vl, cb->store_rates); if (status != 0) { @@ -630,6 +600,7 @@ static int wg_config_carbon (oconfig_item_t *ci) { struct wg_callback *cb; user_data_t user_data; + char callback_name[DATA_MAX_NAME_LEN]; int i; cb = malloc (sizeof (*cb)); @@ -673,17 +644,17 @@ static int wg_config_carbon (oconfig_item_t *ci) } } - DEBUG ("write_graphite: Registering write callback to carbon agent %s:%s", - cb->node ? cb->node : WG_DEFAULT_NODE, - cb->service ? cb->service : WG_DEFAULT_SERVICE); + ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s/%s", + cb->node != NULL ? cb->node : WG_DEFAULT_NODE, + cb->service != NULL ? cb->service : WG_DEFAULT_SERVICE); memset (&user_data, 0, sizeof (user_data)); user_data.data = cb; - user_data.free_func = NULL; - plugin_register_flush ("write_graphite", wg_flush, &user_data); - user_data.free_func = wg_callback_free; - plugin_register_write ("write_graphite", wg_write, &user_data); + plugin_register_write (callback_name, wg_write, &user_data); + + user_data.free_func = NULL; + plugin_register_flush (callback_name, wg_flush, &user_data); return (0); }