1

I am newbie to metrics and I don't understand why I am getting this output Please somebody explain. Thanks in advance.

package sample;
  import com.codahale.metrics.*;
  import java.util.concurrent.TimeUnit;

  public class GetStarted {
    static final MetricRegistry metrics = new MetricRegistry();
    public static void main(String args[]) {
      startReport();
      Meter requests = metrics.meter("requests");
      requests.mark();
      wait5Seconds();
    }

  static void startReport() {
      ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
          .convertRatesTo(TimeUnit.SECONDS)
          .convertDurationsTo(TimeUnit.MILLISECONDS)
          .build();
      reporter.start(1, TimeUnit.SECONDS);
  }

  static void wait5Seconds() {
      try {
          Thread.sleep(5*1000);
      }
      catch(InterruptedException e) {}
  }
}

Output :

12/18/15 12:01:15 PM ===========================================================

-- Meters ---------------------------------------------------------------------- requests count = 1 mean rate = 1.00 events/second 1-minute rate = 0.00 events/second 5-minute rate = 0.00 events/second 15-minute rate = 0.00 events/second

12/18/15 12:01:16 PM ===========================================================

-- Meters ---------------------------------------------------------------------- requests count = 1 mean rate = 0.50 events/second 1-minute rate = 0.00 events/second 5-minute rate = 0.00 events/second 15-minute rate = 0.00 events/second

12/18/15 12:01:17 PM ===========================================================

-- Meters ---------------------------------------------------------------------- requests count = 1 mean rate = 0.33 events/second 1-minute rate = 0.00 events/second 5-minute rate = 0.00 events/second 15-minute rate = 0.00 events/second

12/18/15 12:01:18 PM ===========================================================

-- Meters ---------------------------------------------------------------------- requests count = 1 mean rate = 0.25 events/second 1-minute rate = 0.00 events/second 5-minute rate = 0.00 events/second 15-minute rate = 0.00 events/second

12/18/15 12:01:19 PM ===========================================================

-- Meters ---------------------------------------------------------------------- requests count = 1 mean rate = 0.20 events/second 1-minute rate = 0.00 events/second 5-minute rate = 0.00 events/second 15-minute rate = 0.00 events/second

6
  • 2
    Can you share what was your expectation for the output? Commented Dec 18, 2015 at 6:53
  • 1
    Are you confused by the fact that on the one hand you see ´requests count=1` and on the other some of your rates are 0.00 ? Have a look at mark(), it increases the count by 1 already. Commented Dec 18, 2015 at 7:02
  • @RajnikantPatel I am learning newly. I just want to understand how im getting this output. Commented Dec 18, 2015 at 7:10
  • @Marged Yes . and also wat is 1 min rate and 15 min rate. Commented Dec 18, 2015 at 7:11
  • @Marged Could you help me by sharing some tutorial links or some resource to learn metrics. Commented Dec 18, 2015 at 10:06

1 Answer 1

4

After creating registry, you have started the reporter with 1 second interval. So for each second, your console reporter will output to console.

You have chosen meter type metric which will give you count(no of times this event occurred) and mean rate (average rate). Other rates will be zero because a single time unit of that measurement is not yet over. Eg. You ran the program only for 5 seconds so you will not get 1 minute rate. Let it run for more than 1 minute you can see other rates with some value.

requests.mark();

The above line is used to mark the occurrence of an event. As you have invoked it once a metric event will be triggered. As you are not calling this method any more in the program, so count remains 1.

mean rate is (total count from start of application)/(total time in secs from start). Note: here it is seconds. For every second reporter is printing. As count=1, at 1st sec rate= (1 count)/(1sec). at 2nd sec rate = (1 count)/(2 sec)=0.5 , at 3rd sec rate = (1 count)/(3 sec) = 0.33

1 min rate is (total count in last 1 min)/(60 secs). 1 min rates here it is zero because still 1 minute has not passed. Same for the following big interval rates

5 min rate is (total count in last 5 min)/(5*60 secs) . 5 mins = 5*60 secs

You might expect the thread to sleep and thereby expecting a gap of 5 secs in the log. But the reporter is running in a different thread. So here sleeping for 5 secs is of no value except make the program run to 5 seconds.

Sign up to request clarification or add additional context in comments.

6 Comments

can you accept the answer if it makes sense and is understandable
Could you help me by sharing some tutorial links or some resource to learn metrics.
Thanks . Apart from this.
getting started section of dropwizard link above contains most of the required stuff. what is it you want to know more about?
I am going through the dropwizard link already but not able understanding properly. So looking for some detailed example programs.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.