如何读取和复位弹簧执行器指标?
作者:互联网
我正在使用spring-boot.1.3.0,它提供了在内存中存储自定义指标的功能,如下所示:
@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读取计数值?
解决方法:
@Autowired
private BufferMetricReader metrics;
int count = metrics.findOne("my.metrics.key").getValue().intValue();
标签:spring-boot-actuator,spring,spring-boot,metrics 来源: https://codeday.me/bug/20190727/1556927.html