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?
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.
"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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With