Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Dropwizard计数器未在Spring Boot应用程序中保留值_Spring Boot_Dropwizard_Graphite_Codahale Metrics - Fatal编程技术网

Spring boot Dropwizard计数器未在Spring Boot应用程序中保留值

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

我正在尝试在我的pvt云环境中注册spring boot应用程序的数量。逻辑是使用计数器度量在启动期间递增,在关闭期间递减。所有不同的部署将发布到相同的metricPreFix。下面是我在Graphite中得到的图表:

为什么即使在应用程序运行时,我也会看到值降到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();
}
}
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);
}