0

我正在尝试注册我在 pvt 云环境中的 spring boot 应用程序的数量。逻辑是在启动和关闭期间使用Counter度量。所有不同的部署将发布到相同的(--假设)。以下是我在 Graphite 中得到的图表:incrementdecrementmetricPreFix
计数器与时间

#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();
}
}
4

1 回答 1

1

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

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

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

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

于 2017-06-08T06:12:35.870 回答