spring-boot指标与spring-cloud指标

gad*_*s00 12 spring-boot spring-cloud

我一直在使用spring-boot中的指标,并对Spring-cloud如何改变行为产生一些混乱.

一个简单的最小弹簧启动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;
    }
}
Run Code Online (Sandbox Code Playgroud)

此应用程序的度量标准端点具有

...
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
Run Code Online (Sandbox Code Playgroud)

这是在spring-boot docs中描述的.我的自定义计数器(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,
Run Code Online (Sandbox Code Playgroud)

正常的MVC指标消失了.响应代码信息在哪里?我的自定义计数器报告为gauge.servo.counter.calls.hello,但它不再作为计数器工作,它似乎只显示值1,即使我已经对HelloController进行了5次调用.稍微调试和搜索使我将计数器度量名称更改为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,
Run Code Online (Sandbox Code Playgroud)

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

有关指标的Spring-cloud文档似乎表明我应该使用ServoRegistry,无论是使用伺服还是旁观者.观众指标部分中的术语是不同的.柜台不按照我的预期运作.当我使用文档中描述的使用ServoRegistry发布一个简单的点击计数器时,我在度量标准端点中获得某种速率.

伺服和/或观众对弹簧靴提供的内容有一些附加价值吗?Spring-cloud文档表明,有更多信息记录到默认控制器指标,但它们没有显示在/ metrics中.我应该只是排除ServoMetricsAutoConfiguration并使用spring-boot实现吗?

Jon*_*ahl 6

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

春季启动

"counter.status.200.root": 20
"counter.status.400.root": 3
Run Code Online (Sandbox Code Playgroud)

Netflix公司

"root(method=GET,status=200,statistic=count)": 20
"root(method=GET,status=400,statistic=count)": 3
Run Code Online (Sandbox Code Playgroud)

维度指标允许更多查询灵活性,默认情况下,MVC请求使用HTTP方法,HTTP状态,URI和异常进行标记(如果请求处理程序引发异常).

不幸的是,尺寸Netflix指标在/metrics执行器端点中显示时似乎不能很好地转换,因此如果您需要的只是Spring Boot在指标端点中提供的默认请求计数器,您最好禁用伺服配置:

spring.metrics.servo.enabled=false
Run Code Online (Sandbox Code Playgroud)