github / brubeck

A Statsd-compatible metrics aggregator
MIT License
1.19k stars 94 forks source link

What is the counter's behavior? #27

Closed liyichao closed 9 years ago

liyichao commented 9 years ago

In the brubeck/metric.c, there is this:

static void
counter__record(struct brubeck_metric *metric, value_t value)
{
    pthread_spin_lock(&metric->lock);
    {
        if (metric->as.counter.previous > 0.0) {
            value_t diff = (value >= metric->as.counter.previous) ?
                (value - metric->as.counter.previous) :
                (value);

            metric->as.counter.value += diff;
        }

        metric->as.counter.previous = value;
    }
    pthread_spin_unlock(&metric->lock);
}

Think there are two servers reporting the same counter http_requests, first one server sends 5, and the metric->as.counter.value is 5, then the second server sends 10, metric->as.counter.value is 10, but we expect the counter to be 15. Am I right?

Dieken commented 9 years ago

The meter in brubeck is same with counter in etsy/statsd, I also don't understand what the purpose of "counter" in brubeck here is, the logic above is confusing.

vmg commented 9 years ago

Think there are two servers reporting the same counter http_requests, first one server sends 5, and the metric->as.counter.value is 5, then the second server sends 10, metric->as.counter.value is 10, but we expect the counter to be 15. Am I right?

You're thinking of a "meter" (special character c). A counter is like a meter but always monotonically increasing (special character C). The nomenclature is not exactly the same as in StatsD, but the packet and metric types are 100% compatible; some StatsD implementations just don't support the C-kind of metrics.

Sorry for the confusion!