@TOC
Hystrix仪表盘(Hystrix Dashboard),就像汽车的仪表盘实时显示汽车的各项数据一
样,Hystrix仪表盘主要用来监控Hystrix 的实时运行状态,通过它概们可以看到 Hystrix的各
项指标信息,从而快速发现系统中存在的问题进而解决它。
要使用Hystrix仪表盘功能,我们首先需要有一个Hystrix Dashboard:这个功能我们可以
在原来的消费者应用上添加,让原来的消费者应用具备Hystrix仪表盘功能,但一般地,微服
务架构思想是推崇服务的拆分,Hystrix Dashboard 也是一个服务,所以通常会单独创建一个
新的工程专门用做 Hystrix Dashboard服务;
搭建一个Hystrix Dashboard服务的步骤
1.创建一个普通的Spring Boot项目
2.添加Hystrix Dashboard pom依赖
<!-- Hystrix Dashboard 底层实际上用了springboot所以不需要再倒入springboot-starter-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
3.在入口类添加注解
@SpringBootApplication
//开启Hystrix 仪表盘功能
@EnableHystrixDashboard
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
4.属性配置yml
server:
port: 8086
5.启动仪表盘 http://localhost:端口(仪表盘):hystrix
1.仪表盘地址
2.需要监控的服务地址
3.轮询监控延迟时间 默认 2000ms
4.仪表盘标题 默认使用URL
Hystrix监控 (springboot2.0版本后URL:http://localhost:8082/hystrix.stream)
而不是http://localhost:8082/actuator/hystrix.stream
1.消费者项目需要hystrix的依赖
<!--Spring CLoud熔断器起步依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
2.需要一个spring boot 的服务监控依赖
<!-- springboot的服务监控依赖 探查springboot健康检查运行状态-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
3.yml配置文件 配置springboot监控断点的访问权限
# 暴露endpoints的,由于endpoints会包含很多敏感信息,除了health和info两个直接支持外,其他默认的都不能访问,所以我们让他都能访问,或者指定
management:
endpoints:
web:
exposure:
# *表示所有的端点都允许访问
include: *
# 或者指定成特定的 , 正常都会指定
management:
endpoints:
web:
exposure:
include: hystrix.stream