【问题标题】:spring-boot metrics vs spring-cloud metricsspring-boot 指标与 spring-cloud 指标
【发布时间】:2016-07-24 20:15:37
【问题描述】:

我一直在使用 spring-boot 中的指标,并且对 spring-cloud 似乎如何改变行为感到有些困惑。

一个简单的最小 spring-boot 1.3.3.RELEASE 应用程序,带有执行器和单个控制器:

@RestController
public class HelloController {

    @Autowired
    private CounterService counterService;

    @RequestMapping("/hello")
    public String sayHello(@RequestParam("name") String name) {
        counterService.increment("counter.calls.hello");
        return "Hello, " + name;
    }
}

此应用程序的指标端点具有

...
gauge.response.hello: 5,
gauge.response.metrics: 69,
gauge.response.star-star.favicon.ico: 2,
counter.status.200.star-star.favicon.ico: 4,
counter.status.200.metrics: 1,
counter.calls.hello: 5,
counter.status.200.hello: 5

如 spring-boot 文档中所述。我的自定义计数器 (counter.calls.hello) 按预期用作计数器。

现在,如果我将 spring-cloud-starter-eureka (Brixton.RC1) 添加到我的 pom 并且不更改任何其他内容,则指标端点有

...
gauge.servo.counter.calls.hello: 1,
normalized.servo.rest.totaltime: 0,
normalized.servo.rest.count: 0,
gauge.servo.rest.min: 0,
gauge.servo.rest.max: 0,
gauge.servo.response.hello: 7,
gauge.servo.response.star-star.favicon.ico: 2,

正常的 MVC 指标已经消失。响应代码信息在哪里?我的自定义计数器被报告为 gauge.servo.counter.calls.hello,但它不再用作计数器,即使我对 HelloController 进行了 5 次调用,它似乎也只显示值 1。一些调试和搜索使我将计数器指标名称更改为meter.calls.hello,这会在指标响应中产生counter.servo.calls.hello,并恢复计数器功能。

进一步阅读表明 spring-cloud 正在默认伺服指标,并表明如果我使用的是 java 8,我应该使用旁观者。将 spring-cloud-starter-spectator 添加到我的 pom 中,并返回“counter.calls.hello”作为计数器指标名称,指标端点有

...
counter.calls.hello(): 3,
response.hello(): 7,
response.metrics(): 9,
response.star-star.favicon.ico(): 2,

这对其余端点的内置信息更少,但我的自定义计数器似乎确实起作用。

关于指标的 Spring-cloud 文档似乎表明我应该使用 ServoRegistry,无论是使用伺服还是旁观者。观众指标部分的术语不同。计数器不能按我预期的方式工作。当我按照文档中的描述使用 ServoRegistry 发布一个简单的命中计数器时,我会在指标端点中返回某种速率。

伺服和/或旁观者是否比 spring-boot 提供的附加值? Spring-cloud 文档表明有更多信息记录到默认控制器指标中,但它们没有显示在 /metrics 中。我应该排除 ServoMetricsAutoConfiguration 并使用 spring-boot 实现吗?

【问题讨论】:

    标签: spring-boot spring-cloud


    【解决方案1】:

    根据Spring Cloud Brixton documentation,Servo/Spectator 指标的优势在于它们被标记(也称为维度),而常规 Spring Boot 指标是分层的。

    春季启动

    "counter.status.200.root": 20
    "counter.status.400.root": 3
    

    Netflix

    "root(method=GET,status=200,statistic=count)": 20
    "root(method=GET,status=400,statistic=count)": 3
    

    维度指标允许更多的查询灵活性,默认情况下,MVC 请求标记有 HTTP 方法、HTTP 状态、URI 和异常(如果请求处理程序抛出异常)。

    不幸的是,维度 Netflix 指标在 /metrics 执行器端点中显示时似乎不能很好地转换,所以如果您只需要 Spring Boot 在指标端点中提供的默认请求计数器,您会更好关闭禁用伺服配置:

    spring.metrics.servo.enabled=false
    

    【讨论】:

      猜你喜欢
      • 2020-10-26
      • 2018-01-11
      • 2021-08-01
      • 2015-09-03
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 2020-07-14
      相关资源
      最近更新 更多