Spring 启动自动配置指标未到达 Librato

Spring Boot auto-configured metrics not arriving to Librato

我正在使用 Spring 启用自动配置 (@EnableAutoConfiguration) 的引导,并尝试将我的 Spring MVC 指标发送到 Librato。现在只有我自己创建的指标会到达 Librato,但自动配置的指标(CPU、文件描述符等)不会发送给我的记者。

如果我访问一个度量端点,我可以看到那里生成的信息,例如 http://localhost:8081/actuator/metrics/system.cpu.count

我的代码基于 ConsoleReporter 的 this post。所以我有这个:

public static MeterRegistry libratoRegistry() {
    MetricRegistry dropwizardRegistry = new MetricRegistry();

    String libratoApiAccount = "xx";
    String libratoApiKey = "yy";
    String libratoPrefix = "zz";

    LibratoReporter reporter = Librato
            .reporter(dropwizardRegistry, libratoApiAccount, libratoApiKey)
            .setPrefix(libratoPrefix)
            .build();
    reporter.start(60, TimeUnit.SECONDS);

    DropwizardConfig dropwizardConfig = new DropwizardConfig() {
        @Override
        public String prefix() {
            return "myprefix";
        }

        @Override
        public String get(String key) {
            return null;
        }
    };

    return new DropwizardMeterRegistry(dropwizardConfig, dropwizardRegistry, HierarchicalNameMapper.DEFAULT, Clock.SYSTEM) {
        @Override
        protected Double nullGaugeValue() {
            return null;
        }
    };
}

在我的主要功能中,我添加了 Metrics.addRegistry(SpringReporter.libratoRegistry());

对于我在 compile("com.librato.metrics:metrics-librato:5.1.2") build.gradle 中使用的 Librato 库。文档 here。我以前用过这个库没有任何问题。

如果我像 this post 那样使用 ConsoleReporter,同样的事情会发生,只有我自己创建的指标会打印到控制台。

对我做错了什么有什么想法吗?或者我错过了什么?

此外,我启用了调试模式以查看控制台中打印的 "CONDITIONS EVALUATION REPORT",但不确定在那里寻找什么。

试着让你的 MeterRegistry for Librato 记者成为 Spring @Bean 让我知道它是否有效。


更新:

我用你提到的 ConsoleReporter 进行了测试,并确认它可以与 a sample 一起使用。 请注意,示例位于分支 console-reporter,而不是 master 分支。有关详细信息,请参阅示例。