【问题标题】:Dropwizard Counter Not Retaining value in Spring Boot AppDropwizard 计数器在 Spring Boot 应用程序中未保留值
【发布时间】:2017-05-30 12:28:10
【问题描述】:

我正在尝试注册我在我的 pvt 云环境中拥有的 # 个 Spring Boot 应用程序。逻辑是在启动期间使用Counter 度量到increment,在关闭期间使用decrement。所有不同的部署都将发布到相同的metricPreFix(--assumption)。
以下是我在 Graphite 中得到的图表:

#application.properties
spring.metrics.export.delay-millis=100

为什么即使应用程序正在运行,我也看到该值下降到 0?我尝试了两种不同的实现,结果相同。有人可以指出我理解的差距吗? PFB代码

@Component
public class AppStartupBean implements CommandLineRunner {

private static final String appMetricName = "MyApp.currentCount.GraphOne";
private static final String metricName = "MyApp.currentCount.GraphTwo";

@Autowired
DropwizardMetricServices dwMetricService;

@Autowired
private MetricRegistry registry;

@Override
public void run(String... arg0) throws Exception {
    dwMetricService.increment(appMetricName);

    Counter counter = registry.counter(metricName);
    counter.inc();
}
}

【问题讨论】:

    标签: spring-boot dropwizard graphite codahale-metrics


    【解决方案1】:

    DropwizardMetricServices 的配置错误。我正在使用

    @Bean
    public DropwizardMetricServices dwMetricService(MetricRegistry registry) {
         return new DropwizardMetricServices(registry);
    }
    

    相反,我们应该只根据需要@Autowire DropwizardMetricServices。 PFB

    使用 Dropwizard 指标时,默认的 CounterService 和 GaugeService 被替换为 DropwizardMetricServices,它是 围绕 MetricRegistry 的包装器(因此您可以 @Autowired 其中一个 服务并正常使用)。

    【讨论】:

      猜你喜欢
      • 2019-08-06
      • 2018-02-16
      • 2017-05-24
      • 2015-11-30
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多