我正在为带有注解的grails应用程序配置dropwizard指标。使用metrics-aspectj插件(https://github.com/astefanutti/metrics-aspectj)

我在“BuildConfig.groovy”中有以下内容

compile 'io.astefanutti.metrics.aspectj:metrics-aspectj:1.1.0'
compile 'io.dropwizard.metrics:metrics-core:3.1.0'
compile 'io.dropwizard.metrics:metrics-graphite:3.1.2'
compile 'io.dropwizard.metrics:metrics-annotation:3.1.2'

在这里,我试图将数据发布到本地运行的Graphite服务器。
我已经用石墨报告器配置了如下 Controller 。当我运行该应用程序时,它不会报告任何内容,我试图找出错误之处,或者如果有其他方法(例如,使用spring AOP),请告诉我。
import com.codahale.metrics.ConsoleReporter
import com.codahale.metrics.MetricFilter
import com.codahale.metrics.MetricRegistry
import com.codahale.metrics.SharedMetricRegistries
import com.codahale.metrics.annotation.Metered
import com.codahale.metrics.annotation.Timed
import com.codahale.metrics.graphite.Graphite
import com.codahale.metrics.graphite.GraphiteReporter
import io.astefanutti.metrics.aspectj.Metrics

import java.util.concurrent.TimeUnit

@Metrics(registry = "graphiteregistry2")
class GlassdoorController {


    final MetricRegistry registry = new MetricRegistry();

    GlassdoorController() {

        final Graphite graphite = new Graphite(new InetSocketAddress("127.0.0.1", 2003));

        final GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
                .prefixedWith("grails.example.com")
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .filter(MetricFilter.ALL)
                .build(graphite);
        reporter.start(1, TimeUnit.SECONDS);

        ConsoleReporter reporter1 = ConsoleReporter.forRegistry(registry)
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .build();
        reporter1.start(5, TimeUnit.SECONDS)

        SharedMetricRegistries.add("graphiteregistry2",registry);
        log.info(SharedMetricRegistries.getOrCreate("graphiteregistry2"));
    }

    @Metered(name  = "reviewspage")
    @Timed(name = "reviewspagetimed")
    def reviews() {

        //business logic

    }

最佳答案

查看您的代码,我发现了一个不同之处:

reporter.start(1, TimeUnit.SECONDS);
// ...
reporter1.start(5, TimeUnit.SECONDS)

这意味着您的Graphite报告器每秒触发一次,但控制台报告器仅每5秒触发一次。在这5秒钟结束之前,您的测试程序可能已经存在。因此,您可以在Thread.sleep(6000)方法中添加一些main()或减少控制台报告程序与Graphite报告程序匹配的报告时间间隔。我试过了,行得通。 ;-)
06.03.16 12:22:59 ==============================================================

-- Meters ----------------------------------------------------------------------
de.scrum_master.app.GlassdoorController.reviewspage
             count = 1
         mean rate = 0,20 events/second
     1-minute rate = 0,20 events/second
     5-minute rate = 0,20 events/second
    15-minute rate = 0,20 events/second

-- Timers ----------------------------------------------------------------------
de.scrum_master.app.GlassdoorController.reviewspagetimed
             count = 1
         mean rate = 0,20 calls/second
     1-minute rate = 0,20 calls/second
     5-minute rate = 0,20 calls/second
    15-minute rate = 0,20 calls/second
               min = 0,01 milliseconds
               max = 0,01 milliseconds
              mean = 0,01 milliseconds
            stddev = 0,00 milliseconds
            median = 0,01 milliseconds
              75% <= 0,01 milliseconds
              95% <= 0,01 milliseconds
              98% <= 0,01 milliseconds
              99% <= 0,01 milliseconds
            99.9% <= 0,01 milliseconds

08-28 03:36