我使用Spring并启用了自动配置(@EnableAutoConfiguration),并试图将Spring指标发送到Librato。现在只有我自己创建的指标到达Librato,但是自动配置的度量(CPU、文件描述符等)没有发送给我的记者。
如果我访问一个度量端点,我可以看到在那里生成的信息,例如http://localhost:8081/actuator/metrics/system.cpu.count
我的代码是基于这个职位 for ConsoleReporter的。所以我有这个:
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库来说。文档这里。我以前使用过这个图书馆,没有任何问题。
如果我像在ConsoleReporter中一样使用这个职位,那么只有我自己创建的度量被打印到控制台。
对我做错了什么有什么想法吗?或者我错过了什么?
此外,我启用了调试模式,以查看控制台中打印的“条件评估报告”,但不确定在其中查找什么。
发布于 2018-08-09 14:20:21
试着让Librato记者的MeterRegistry成为一个Spring @Bean,并让我知道它是否有效。
更新:
我用您提到的ConsoleReporter进行了测试,并确认它正在与一个例子一起工作。注意,示例位于分支console-reporter**,上,而不是** master 分支上。查看示例以获取详细信息。
https://stackoverflow.com/questions/51769134
复制相似问题