statsd plugin: add TimerCount option
authorMarc Fournier <marc.fournier@camptocamp.com>
Fri, 26 Jul 2013 15:35:44 +0000 (17:35 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Wed, 14 Aug 2013 14:33:37 +0000 (16:33 +0200)
The "count" name was chosen over "num" to match the naming scheme
used by the node.js implementation.

src/statsd.c
src/utils_latency.c
src/utils_latency.h

index 731a6e8..72a7779 100644 (file)
@@ -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);
   }
index 4a250c3..94da211 100644 (file)
@@ -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;
index 352a4ec..3787c77 100644 (file)
@@ -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);