本文主要是介绍spring-boot-发布自定义度量信息,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、 CounterService(inc,dec,reset)与GaugeService(submit更新)
@RestController
public class AppleCtrl {@Autowiredprivate CounterService counterService;@Autowiredprivate GaugeService gaugeService;@RequestMapping("/test.do")public String ss(){counterService.increment("jasmine.count");gaugeService.submit("jasmine.time",System.currentTimeMillis());return "ok";}
}
查看:http://localhost/metrics/counter.jasmine.count
http://localhost/metrics/gauge.jasmine.time
2、自定义
@Component
public class AppleMetrics implements PublicMetrics{@Autowiredprivate ApplicationContext context;@Overridepublic Collection<Metric<?>> metrics() {List<Metric<?>> metrics = new ArrayList<Metric<?>>();metrics.add(new Metric<Number>("jasmine.spring.bean.count",context.getBeanDefinitionCount()));return metrics;}}
访问:http://localhost/metrics/jasmine.spring.bean.count
这篇关于spring-boot-发布自定义度量信息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!