From: Casey Tucker Date: Tue, 21 Sep 2021 08:39:17 +0000 (-0700) Subject: add CounterGauge option in statsd (#3914) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc2807077972b9adb603e9c838485a3bd6701db1;p=thirdparty%2Fcollectd.git add CounterGauge option in statsd (#3914) --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index f5b4fdcdc..6f06184cd 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1719,6 +1719,7 @@ # DeleteGauges false # DeleteSets false # CounterSum false +# CounterGauge false # TimerPercentile 90.0 # TimerPercentile 95.0 # TimerPercentile 99.0 diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 43855bdb4..80e0d0492 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -9130,6 +9130,13 @@ When enabled, creates a C metric which reports the change since the last read. This option primarily exists for compatibility with the I implementation by Etsy. +=item B B|B + +When enabled, creates a C metric which reports counters as a "gauge" +of the differential, resetting the counter between flush intervals. This +option primarily exists for compatibility with the I implementation +in GitHub Enterprise Server. + =item B I Calculate and dispatch the configured percentile, i.e. compute the latency, so diff --git a/src/statsd.c b/src/statsd.c index 9050596f9..3d852ccde 100644 --- a/src/statsd.c +++ b/src/statsd.c @@ -80,6 +80,7 @@ static double *conf_timer_percentile; static size_t conf_timer_percentile_num; static bool conf_counter_sum; +static bool conf_counter_gauge; static bool conf_timer_lower; static bool conf_timer_upper; static bool conf_timer_sum; @@ -636,6 +637,8 @@ static int statsd_config(oconfig_item_t *ci) /* {{{ */ cf_util_get_boolean(child, &conf_delete_gauges); else if (strcasecmp("DeleteSets", child->key) == 0) cf_util_get_boolean(child, &conf_delete_sets); + else if (strcasecmp("CounterGauge", child->key) == 0) + cf_util_get_boolean(child, &conf_counter_gauge); else if (strcasecmp("CounterSum", child->key) == 0) cf_util_get_boolean(child, &conf_counter_sum); else if (strcasecmp("TimerLower", child->key) == 0) @@ -806,6 +809,43 @@ static int statsd_metric_submit_unsafe(char const *name, sstrncpy(vl.type, "derive", sizeof(vl.type)); } + /* + * From: Vicent Marti + * Date: Mon, 15 Dec 2014 17:07:28 +0100 + * Subject: [PATCH] Report Counters using the same behavior as StatsD + * + * The current implementation is not really compatible with what the + * reference StatsD implementation does. StatsD aggregates the increase in + * the counter during the flushing interval, and at flush, reports the + * current value as a differential and resets the counter. + * + * The implementation in Collectd instead never resets the counter, and + * always reports the *absolute* value to RRD as a DERIVE, assuming it will + * perform the differential itself. This behavior is rather surprising, + * particularly when graphing with tools that expect to be + * Graphite-compatible. + * + * This patch implements the right behavior by reporting counters as a + * "gauge" of the differential (i.e. resetting the counter between flush + * intervals). This mimics StatsD's behavior, and even the same behavior + * that Collectd performs when reporting the "count" row in a histogram -- + * after all, the count row in the histogram should have the same semantics + * as a counter metric. This was previously inconsistent in this + * implementation. */ + if (conf_counter_gauge) { + gauge_t previous_gauge = vl.values[0].gauge; + + sstrncpy(vl.type, "gauge", sizeof(vl.type)); + vl.values[0].gauge = (gauge_t)metric->value; + metric->value = 0.0; + plugin_dispatch_values(&vl); + + /* restore vl.type and values[0].gauge */ + sstrncpy(vl.type, "derive", sizeof(vl.type)); + metric->value = vl.values[0].gauge; + vl.values[0].gauge = previous_gauge; + } + /* Rather than resetting value to zero, subtract delta so we correctly keep * track of residuals. */ metric->value -= delta;