From: Marc Fournier Date: Fri, 26 Jul 2013 15:35:44 +0000 (+0200) Subject: statsd plugin: add TimerCount option X-Git-Tag: collectd-5.4.0~8 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=06af7097ff0c9f97667774ab658e560f0950a23f;p=collectd.git statsd plugin: add TimerCount option The "count" name was chosen over "num" to match the naming scheme used by the node.js implementation. --- diff --git a/src/statsd.c b/src/statsd.c index 731a6e8c..72a7779b 100644 --- a/src/statsd.c +++ b/src/statsd.c @@ -82,6 +82,7 @@ static size_t conf_timer_percentile_num = 0; static _Bool conf_timer_lower = 0; static _Bool conf_timer_upper = 0; static _Bool conf_timer_sum = 0; +static _Bool conf_timer_count = 0; /* Must hold metrics_lock when calling this function. */ static statsd_metric_t *statsd_metric_lookup_unsafe (char const *name, /* {{{ */ @@ -635,6 +636,8 @@ static int statsd_config (oconfig_item_t *ci) /* {{{ */ cf_util_get_boolean (child, &conf_timer_upper); else if (strcasecmp ("TimerSum", child->key) == 0) cf_util_get_boolean (child, &conf_timer_sum); + else if (strcasecmp ("TimerCount", child->key) == 0) + cf_util_get_boolean (child, &conf_timer_count); else if (strcasecmp ("TimerPercentile", child->key) == 0) statsd_config_timer_percentile (child); else @@ -770,6 +773,16 @@ static int statsd_metric_submit_unsafe (char const *name, /* {{{ */ plugin_dispatch_values (&vl); } + /* Keep this at the end, since vl.type is set to "gauge" here. The + * vl.type's above are implicitly set to "latency". */ + if (conf_timer_count) { + sstrncpy (vl.type, "gauge", sizeof (vl.type)); + ssnprintf (vl.type_instance, sizeof (vl.type_instance), + "%s-count", name); + values[0].gauge = latency_counter_get_num (metric->latency); + plugin_dispatch_values (&vl); + } + latency_counter_reset (metric->latency); return (0); } diff --git a/src/utils_latency.c b/src/utils_latency.c index 4a250c33..94da2112 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -117,6 +117,13 @@ cdtime_t latency_counter_get_sum (latency_counter_t *lc) /* {{{ */ return (lc->sum); } /* }}} cdtime_t latency_counter_get_sum */ +size_t latency_counter_get_num (latency_counter_t *lc) /* {{{ */ +{ + if (lc == NULL) + return (0); + return (lc->num); +} /* }}} size_t latency_counter_get_num */ + cdtime_t latency_counter_get_average (latency_counter_t *lc) /* {{{ */ { double average; diff --git a/src/utils_latency.h b/src/utils_latency.h index 352a4ec3..3787c779 100644 --- a/src/utils_latency.h +++ b/src/utils_latency.h @@ -39,6 +39,7 @@ void latency_counter_reset (latency_counter_t *lc); cdtime_t latency_counter_get_min (latency_counter_t *lc); cdtime_t latency_counter_get_max (latency_counter_t *lc); cdtime_t latency_counter_get_sum (latency_counter_t *lc); +size_t latency_counter_get_num (latency_counter_t *lc); cdtime_t latency_counter_get_average (latency_counter_t *lc); cdtime_t latency_counter_get_percentile (latency_counter_t *lc, double percent);