Hystrix仪表盘

时间:2022-07-22
本文章向大家介绍Hystrix仪表盘,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

除了服务熔断、降级的功能外,Hystrix 还提供了准及时的调用监控。 Hystrix 会持续地记录所有通过 Hystrix 发起的请求的执行信息,并以统计报表和图形方式展示给用户。

配置被监控方

order-server 项目中:

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

修改 application.yml,开放端口:

management:
  endpoints:
    web:
      exposure:
        include: "*"

配置监控方

新建一个名为 hystrix-dashboard 项目,添加如下依赖:

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

新建 application.yml

server:
  port: 9300
  
spring:
  application:
    name: Hystrix-Dashboard  

开启监控功能 在启动类上添加 @EnableHystrixDashboard 注解。

@EnableHystrixDashboard
@SpringBootApplication
public class HystrixdashboardApplication {

	public static void main(String[] args) {
		SpringApplication.run(HystrixdashboardApplication.class, args);
	}
}

启动,浏览器访问: http://localhost:9300/hystrix

监控设置

我们以监控 order-server 为例,在监控界面添加监控信息:

# 需要监控的服务地址
http://localhost:8100/actuator/hystrix.stream

delay: 请求间隔时间

title: 监控名称

点击 monitor stream

批量访问 order-server 服务的下单接口。

最终效果如下:

通过批量访问下单接口,发现图中实心圆和曲线发生了变化。那我们如何根据这两个图形查看监控信息呢?

实心圆:通过颜色的变化代表实例的健康程度,健康度从绿色>黄色>橙色>红色递减。其大小也会根据实例的请求流量发生变化,流量越大实心圆越大。

曲线:用来记录间隔时间内流量的相对变化,通常可以观察到流量的上升和下降趋势。 源码下载