SpringBoot实战电商项目mall(20k+star)地址:github.com/macrozheng/…java
Hystrix Dashboard 是Spring Cloud中查看Hystrix实例执行状况的一种仪表盘组件,支持查看单个实例和查看集群实例,本文将对其用法进行详细介绍。git
Hystrix提供了Hystrix Dashboard来实时监控HystrixCommand方法的执行状况。 Hystrix Dashboard能够有效地反映出每一个Hystrix实例的运行状况,帮助咱们快速发现系统中的问题,从而采起对应措施。github
咱们先经过使用Hystrix Dashboard监控单个Hystrix实例来了解下它的使用方法。web
用来监控hystrix实例的执行状况。spring
<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,启动后注册中心显示以下。express
management:
endpoints:
web:
exposure:
include: 'hystrix.stream' #暴露hystrix监控端点
复制代码
图表解读以下,须要注意的是,小球表明该实例健康状态及流量状况,颜色越显眼,表示实例越不健康,小球越大,表示实例流量越大。曲线表示Hystrix实例的实时流量变化。app
这里咱们使用Turbine来聚合hystrix-service服务的监控信息,而后咱们的hystrix-dashboard服务就能够从Turbine获取聚合好的监控信息展现给咱们了。spring-boot
用来聚合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服务,此时注册中心显示以下。测试
访问Hystrix Dashboard:http://localhost:8501/hystrix
添加集群监控地址,须要注意的是咱们须要添加的是turbine-service的监控端点地址:
springcloud-learning
├── eureka-server -- eureka注册中心
├── user-service -- 提供User对象CRUD接口的服务
├── hystrix-service -- hystrix服务调用测试服务
├── turbine-service -- 聚合收集hystrix实例监控信息的服务
└── hystrix-dashboard -- 展现hystrix实例监控信息的仪表盘
复制代码
mall项目全套学习教程连载中,关注公众号第一时间获取。