天天看點

springcloud系列 (六) 斷路器 Hystrix儀表盤的使用

  1. 對于Hystrix,springcloud還提供了一個儀表盤(Dashboard)進行監控斷路的情況,進而讓開發者監控可能出現的問題。
  2. 首先建立一個工程,引入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>
           
  1. 然後在主類加上注解:

    @EnableHystrixDashboard

    即能啟動Hystrix儀表盤;
  2. 在配置檔案,添加基本配置:
spring:
  application:
    name: hystrix_dashboard
server:
  port: 6001
           
  1. 通路浏覽器http://localhost:6001/hystrix即可看到Hystrix儀表盤的主界面,可以支援三種監控方式。隻看單點監控:隻需要給出http://hystrix-app:port/hystrix.stream。
  2. 此時需要在産品微服務中使用Hystrix,還需要在産品微服務中引入Springboot的監控,spring-boot-starter-actuator依賴。同時添加Actuator的端點暴露:
management:
  endpoints:
    web:
      exposure:
        include: health,info,hystrix.stream
           
  1. 然後在Hystrix Dashboard頁面,輸入http://localhost:9001/actuator/hystrix.stream;Delay:2000;Title:産品監控,即可看到監控頁面。
  2. 如果出現頁面報異常,可以參考此文解決:https://blog.csdn.net/qq_34595792/article/details/108025406

繼續閱讀