我一直在使用spring-boot中的指标,对于spring-cloud似乎如何改变行为,我遇到了一些困惑。
一个简单的最小spring-boot 1.3.3版本的应用程序,带有执行器和单个控制器:
@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是默认的指标伺服器,并指出如果我使用的是java8,我应该使用spectator。将spring-cloud-starter-spectator添加到我的pom中,并返回到"counter.calls.hello“作为计数器指标名称,指标端点具有
...
counter.calls.hello(): 3,
response.hello(): 7,
response.metrics(): 9,
response.star-star.favicon.ico(): 2,关于rest端点的内置信息甚至更少,但我的自定义计数器似乎确实起作用了。
关于指标的Spring-cloud文档似乎表明,我应该使用ServoRegistry,无论是使用伺服还是旁观者。观众指标部分中的术语是不同的。计数器的工作方式和我预期的不一样。当我按照文档中的描述使用ServoRegistry发布一个简单的命中计数器时,我在指标端点中得到了某种速率。
在伺服和/或观众中有没有比spring-boot提供的东西更有价值的东西?Spring-cloud文档表明,有更多信息被记录到默认控制器指标,但它们没有显示在/metrics中。我应该只排除ServoMetricsAutoConfiguration而使用spring-boot实现吗?
发布于 2016-11-27 07:00:12
根据Spring Cloud Brixton documentation的说法,伺服/观众指标的优势是它们被标记(也称为维度),而常规Spring Boot指标是分层的。
Spring Boot
"counter.status.200.root": 20
"counter.status.400.root": 3Netflix
"root(method=GET,status=200,statistic=count)": 20
"root(method=GET,status=400,statistic=count)": 3维度度量允许更多的查询灵活性,默认情况下,MVC请求使用HTTP方法、HTTP状态、URI和异常(如果请求处理程序抛出异常)进行标记。
不幸的是,当维度Netflix指标显示在/metrics执行器端点中时,它们似乎不能很好地转换,所以如果您需要的只是Spring Boot在metrics端点中提供的默认请求计数器,那么您最好禁用Servo配置:
spring.metrics.servo.enabled=falsehttps://stackoverflow.com/questions/36417045
复制相似问题