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 如何读取Spring引导度量值?_Spring Boot_Metrics - Fatal编程技术网

Spring boot 如何读取Spring引导度量值?

Spring boot 如何读取Spring引导度量值?,spring-boot,metrics,Spring Boot,Metrics,我使用Spring引导度量来管理一些特定于域的计数器 我的类中有@Autowired org.springframework.boot.actuate.metrics.CounterService,我正在增加特定于域的事件的度量(解析请求的各个阶段) 我想在我的测试中阅读这些指标(检查我的测试请求是否经过了所有必需的阶段),但在CounterService上没有get方法。我看到CounterService的所有实现都有一些带有度量的private ConcurrentMap,但是没有(干净的)

我使用Spring引导度量来管理一些特定于域的计数器

我的类中有
@Autowired org.springframework.boot.actuate.metrics.CounterService
,我正在增加特定于域的事件的度量(解析请求的各个阶段)

我想在我的测试中阅读这些指标(检查我的测试请求是否经过了所有必需的阶段),但在
CounterService
上没有get方法。我看到
CounterService
的所有实现都有一些带有度量的
private ConcurrentMap
,但是没有(干净的)方法来获得这个数据结构

我使用的是Spring Boot
1.3.5.RELEASE

编辑: 我对集成测试感兴趣,如果可能的话,我不想模拟任何组件


目前,我对/metric端点使用REST调用,并解析返回的json,但我不喜欢这种方法

一种方法是使用模拟
反服务
,然后验证预期方法是否已在模拟上调用


如果您更喜欢集成测试,那么可以使用
MetricReader
读入
CounterService
编写的度量。您应该能够
@Autowire
a
MetricReader
MetricRepository
(后者是
MetricReader
MetricWriter
的组合)并调用
findOne

谢谢,MetricRepository看起来很完美!我看过Spring引导文档,但它描述了另一个用例——将度量导出到Redis和其他数据库。我认为MetricRepository解决了我遇到的另一个问题——我希望HTTP端点(仅供内部或测试使用)能够重置度量。这将使测试更容易。我目前在Jmeter测试中读取度量(生成流量之前和之后)。