Codahale Metrics: using @Timed metrics annotation in plain Java

后端 未结 8 978
南方客
南方客 2020-12-29 03:18

I am trying to add metrics to a plain Java application using codahale metrics. I\'d like to use the @Timed annotation, but it is unclear to me which MetricRegistry it uses,

8条回答
  •  暖寄归人
    2020-12-29 03:35

    Use the built-in MetricRegistry accessed from the bootstrap parameter in the initialize method of your application class.

    @Override
    public void initialize(final Bootstrap bootstrap) {
        final JmxReporter reporter = JmxReporter.forRegistry(bootstrap.getMetricRegistry()).build();
        reporter.start();
    }
    

提交回复
热议问题