Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Dropwizard Counter and Meter count the same?

I would like to know whether there is a difference between the "Counter" and the count maintained by the "Meter" class? I understand the Meter measures rates too, but I am curious to know whether if there were a counter and a meter updated(incremented for Counter) at the same time, I would think both numbers would be same. Am I wrong in this assumption?

like image 402
Seagull Avatar asked Dec 22 '16 21:12

Seagull


People also ask

What is io Dropwizard metrics?

Metrics is a Java library which gives you unparalleled insight into what your code does in production. Metrics provides a powerful toolkit of ways to measure the behavior of critical components in your production environment.

What is m1_rate?

"m1_rate": the event rate for the last one minute. "m5_rate": the event rate for the last five minutes. "m15_rate": the event rate for the last fifteen minutes.


2 Answers

the Meter simply also keeps track of the count of mark events that you have on the meter. It does so in the same way a counter does, thus the Meter is just an object that holds the internals of the counter + the logic to measure the rates of the occurring events too.

Here is a code example:

public class MetricTest {
    public static void main(String[] args) {
        MetricRegistry r = new MetricRegistry();
        Counter counter = r.counter("counter");
        Meter meter = r.meter("meter");

        counter.inc();
        meter.mark();

        System.out.println(counter.getCount());
        System.out.println(meter.getCount());

        counter.inc(10);
        meter.mark(10);

        System.out.println(counter.getCount());
        System.out.println(meter.getCount());
    }
}

Which will print:

1
1
11
11

So yes, if the counter and meter are updated in the same way, they will have the same count. The meter uses the count additionally to calculate the mean rate (in addition to the 1/5/15 - minute one)

I hope that helps,

Artur

like image 60
pandaadb Avatar answered Oct 23 '22 12:10

pandaadb


Counter can be decremented. Meter can not be decremented. So, when counter and meter are used together, the values of "counters" differ when the Counter value is decremented.

like image 27
Shyam Paleti Avatar answered Oct 23 '22 13:10

Shyam Paleti