SpringBoot實戰電商項目mall(20k+star)地址: https://github.com/macrozheng/mall
Hystrix Dashboard 是Spring Cloud中查看Hystrix實例執行狀況的一種儀表盤組件,支持查看單個實例和查看集羣實例,本文將對其用法進行詳細介紹。java
Hystrix提供了Hystrix Dashboard來實時監控HystrixCommand方法的執行狀況。 Hystrix Dashboard能夠有效地反映出每一個Hystrix實例的運行狀況,幫助咱們快速發現系統中的問題,從而採起對應措施。git
咱們先經過使用Hystrix Dashboard監控單個Hystrix實例來了解下它的使用方法。
用來監控hystrix實例的執行狀況。
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
server: port: 8501 spring: application: name: hystrix-dashboard eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8001/eureka/
@EnableHystrixDashboard @EnableDiscoveryClient @SpringBootApplication public class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); } }
此次咱們須要啓動以下服務:eureka-server、user-service、hystrix-service、hystrix-dashboard,啓動後註冊中心顯示以下。
management: endpoints: web: exposure: include: 'hystrix.stream' #暴露hystrix監控端點
圖表解讀以下,須要注意的是,小球表明該實例健康狀態及流量狀況,顏色越顯眼,表示實例越不健康,小球越大,表示實例流量越大。曲線表示Hystrix實例的實時流量變化。
這裏咱們使用Turbine來聚合hystrix-service服務的監控信息,而後咱們的hystrix-dashboard服務就能夠從Turbine獲取聚合好的監控信息展現給咱們了。
用來聚合hystrix-service的監控信息。
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-turbine</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
server: port: 8601 spring: application: name: turbine-service eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8001/eureka/ turbine: app-config: hystrix-service #指定須要收集信息的服務名稱 cluster-name-expression: new String('default') #指定服務所屬集羣 combine-host-port: true #以主機名和端口號來區分服務
@EnableTurbine @EnableDiscoveryClient @SpringBootApplication public class TurbineServiceApplication { public static void main(String[] args) { SpringApplication.run(TurbineServiceApplication.class, args); } }
使用application-replica1.yml配置再啓動一個hystrix-service服務,啓動turbine-service服務,此時註冊中心顯示以下。
springcloud-learning ├── eureka-server -- eureka註冊中心 ├── user-service -- 提供User對象CRUD接口的服務 ├── hystrix-service -- hystrix服務調用測試服務 ├── turbine-service -- 聚合收集hystrix實例監控信息的服務 └── hystrix-dashboard -- 展現hystrix實例監控信息的儀表盤
https://github.com/macrozheng/springcloud-learninggithub
mall項目全套學習教程連載中,關注公衆號第一時間獲取。web