Spring boot Dropwizard计数器未在Spring Boot应用程序中保留值
我正在尝试在我的pvt云环境中注册spring boot应用程序的数量。逻辑是使用计数器度量在启动期间递增,在关闭期间递减。所有不同的部署将发布到相同的metricPreFix。下面是我在Graphite中得到的图表: 为什么即使在应用程序运行时,我也会看到值降到0?我尝试了两种不同的实现,结果相同。有人能指出我在理解上的差距吗?PFB代码Spring boot Dropwizard计数器未在Spring Boot应用程序中保留值,spring-boot,dropwizard,graphite,codahale-metrics,Spring Boot,Dropwizard,Graphite,Codahale Metrics,我正在尝试在我的pvt云环境中注册spring boot应用程序的数量。逻辑是使用计数器度量在启动期间递增,在关闭期间递减。所有不同的部署将发布到相同的metricPreFix。下面是我在Graphite中得到的图表: 为什么即使在应用程序运行时,我也会看到值降到0?我尝试了两种不同的实现,结果相同。有人能指出我在理解上的差距吗?PFB代码 @Component public class AppStartupBean implements CommandLineRunner { private
@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();
}
}
DropwizardMetricServices的配置错误。我在用
@Bean
public DropwizardMetricServices dwMetricService(MetricRegistry registry) {
return new DropwizardMetricServices(registry);
}
相反,我们应该只根据需要@Autowire DropwizardMetricServices。PFB
使用Dropwizard度量时,默认的CounterService和
GaugeService替换为DropwizardMetricServices,这是一个
包装MetricRegistry,以便您可以@Autowired其中一个
服务和正常使用它
@Bean
public DropwizardMetricServices dwMetricService(MetricRegistry registry) {
return new DropwizardMetricServices(registry);
}