【发布时间】:2014-01-09 13:25:12
【问题描述】:
Spring Boot 具有预配置的指标。据我所知,它使用http://metrics.codahale.com/ 库。如何获取 MetricRegistry 对象来添加我的自定义指标?
【问题讨论】:
标签: java spring metrics spring-boot
Spring Boot 具有预配置的指标。据我所知,它使用http://metrics.codahale.com/ 库。如何获取 MetricRegistry 对象来添加我的自定义指标?
【问题讨论】:
标签: java spring metrics spring-boot
http://www.ryantenney.com/metrics-spring/ 完成了一些集成魔术,将 codahale 指标连接到执行器 /health 端点。
有了这个依赖,
compile 'com.ryantenney.metrics:metrics-spring:3.0.0-RC2'
您可以在应用程序配置中“启用指标”
@EnableMetrics
public class ApplicationConfiguration {
...
这允许您使用 @timed 注释对每个请求进行计时:
@Timed
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody
Foo foo() {
...
并将您与MetricRegistry 的其他交互聚合到执行器/health 端点中。
我整理了一个实现这种集成的示例应用程序:
https://github.com/benschw/consul-cluster-puppet/tree/master/demo
并在此处编写了更深入的教程: http://txt.fliglio.com/2014/10/spring-boot-actuator/
【讨论】:
Spring boot 现在支持开箱即用的 Codahale Metrics。
【讨论】:
Spring Boot 还没有使用 Codahale Metrics。如果它在类路径上,计划是支持它作为一个选项。如果您更喜欢这样做,那么MetricRegistry 将在应用程序上下文中,您可以简单地@Autowire 并使用它。您可以在 a branch in my fork 上看到正在进行的工作。
用于添加指标的引导接口是GaugeService 和CounterService。您注入这些并使用它们来记录测量值。当 Codahale 获得支持时,这也将是推荐的入口点,因此您现在可以开始使用它,如果需要,以后可以添加 Codahale 的东西。
【讨论】: