Spring Cloud Hystrix的实时监控功能

  • 内容
  • 评论
  • 相关

在微服务架构中,Hystrix 除了实现容错外,还提供了实时监控功能。在服务调用时,Hystrix 会实时累积关于 HystrixCommand 的执行信息,比如每秒的请求数、成功数等。

更多的指标信息请查看官方文档:https://github.com/Netflix/Hystrix/wiki/Metrics-and-Monitoring。

Hystrix 监控需要两个必备条件:

1)必须有 Actuator 的依赖,代码如下所示。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2)必须有 Hystrix 的依赖,Spring Cloud 中必须在启动类中添加 @EnableHystrix 开启 Hystrix,代码如下所示。

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

我们改造下 hystrix-feign-demo 这个项目,加入上边两段代码的依赖,将 actuator 中的端点暴露出来,访问端点地址(http://localhost:8086/actuator/hystrix.stream),如图 1 所示:

运行结果
图 1  运行结果

本文标题:Spring Cloud Hystrix的实时监控功能

本文地址:https://www.hosteonscn.com/6647.html

评论

0条评论

发表评论

邮箱地址不会被公开。 必填项已用*标注