X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fstatsd.c;h=ba8901b9e842ef494e2789190ee3a9046f03e05a;hb=961ead7ebf855bcb53728734c828378c187f23ce;hp=1512b866a870a12da60a3fce6f969c48b3e9bda9;hpb=bde8c6477baa7410dd04f66087e119f4718132bc;p=collectd.git diff --git a/src/statsd.c b/src/statsd.c index 1512b866..ba8901b9 100644 --- a/src/statsd.c +++ b/src/statsd.c @@ -557,6 +557,7 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */ if (tmp == NULL) { ERROR ("statsd plugin: realloc failed."); + close (fd); continue; } fds = tmp; @@ -846,8 +847,19 @@ static int statsd_metric_submit_unsafe (char const *name, /* {{{ */ else values[0].gauge = (gauge_t) c_avl_size (metric->set); } - else - values[0].derive = (derive_t) metric->value; + else { /* STATSD_COUNTER */ + /* + * Expand a single value to two metrics: + * + * - The absolute counter, as a gauge + * - A derived rate for this counter + */ + values[0].derive = (derive_t) metric->value; + plugin_dispatch_values(&vl); + + sstrncpy(vl.type, "gauge", sizeof (vl.type)); + values[0].gauge = (gauge_t) metric->value; + } return (plugin_dispatch_values (&vl)); } /* }}} int statsd_metric_submit_unsafe */ @@ -924,8 +936,6 @@ static int statsd_shutdown (void) /* {{{ */ void *key; void *value; - pthread_mutex_lock (&metrics_lock); - if (network_thread_running) { network_thread_shutdown = 1; @@ -934,10 +944,12 @@ static int statsd_shutdown (void) /* {{{ */ } network_thread_running = 0; + pthread_mutex_lock (&metrics_lock); + while (c_avl_pick (metrics_tree, &key, &value) == 0) { sfree (key); - sfree (value); + statsd_metric_free (value); } c_avl_destroy (metrics_tree); metrics_tree = NULL;