- 對于Hystrix,springcloud還提供了一個儀表盤(Dashboard)進行監控斷路的情況,進而讓開發者監控可能出現的問題。
- 首先建立一個工程,引入Hystirx儀表盤(Dashboard)的maven依賴:
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix-dashboard -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>
- 然後在主類加上注解:
即能啟動Hystrix儀表盤;@EnableHystrixDashboard
- 在配置檔案,添加基本配置:
spring:
application:
name: hystrix_dashboard
server:
port: 6001
- 通路浏覽器http://localhost:6001/hystrix即可看到Hystrix儀表盤的主界面,可以支援三種監控方式。隻看單點監控:隻需要給出http://hystrix-app:port/hystrix.stream。
- 此時需要在産品微服務中使用Hystrix,還需要在産品微服務中引入Springboot的監控,spring-boot-starter-actuator依賴。同時添加Actuator的端點暴露:
management:
endpoints:
web:
exposure:
include: health,info,hystrix.stream
- 然後在Hystrix Dashboard頁面,輸入http://localhost:9001/actuator/hystrix.stream;Delay:2000;Title:産品監控,即可看到監控頁面。
- 如果出現頁面報異常,可以參考此文解決:https://blog.csdn.net/qq_34595792/article/details/108025406