3

我正在使用spring-boot.1.3.0,它提供了将自定义存储metrics在内存中的能力,如下所示:

@Service
public class MyService {
    private CounterService counterService;
    private GaugeService gaucheService;

    @Autowired
    public MyService(CounterService counterService) {
        this.counterService = counterService;
    }

    public void exampleMethod() {
        this.counterService.increment("services.system.myservice.invoked");
    }
}

问题:如何以编程方式从CounterService和读取计数值?GaugeService

4

3 回答 3

5
@Autowired
private BufferMetricReader metrics;

int count = metrics.findOne("my.metrics.key").getValue().intValue();
于 2015-11-18T11:28:23.220 回答
0

@membersound 的答案有效,但我认为它更好用

@Autowired
private MetricReader metricReader;

代替

@Autowired
private BufferMetricReader metrics;
于 2019-04-18T04:47:27.703 回答