我正在使用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");
    }
}

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

最佳答案

@Autowired
private BufferMetricReader metrics;

int count = metrics.findOne("my.metrics.key").getValue().intValue();

10-07 22:04