Hystrix Dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间,请求成功率等数据。
前提:服务提供者、消费者均需要引入actuator包,需要引入Hystrix熔断,主类增加启动熔断注解EnableCircuitBreaker
服务提供者
HystrixConfig.java
@Configuration
public class HystrixConfig {
// 解决spring boot 2.0如下提示的问题
// Unable to connect to Command Metric Stream
@Bean
public ServletRegistrationBean getHystrixBean() {
ServletRegistrationBean hystrix = new ServletRegistrationBean(
new HystrixMetricsStreamServlet(), "/hystrix.stream");
hystrix.setName("hystrixServlet");
hystrix.setLoadOnStartup(1);
return hystrix;
}
}
服务消费者
HystrixConfig.java 同上
服务注册中心
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
CloudApplication.java 启用Hystrix Dashboard注解
@SpringBootApplication
@EnableEurekaServer
@EnableHystrixDashboard
public class CloudApplication {
public static void main(String[] args) {
SpringApplication.run(CloudApplication.class, args);
}
}
测试
hystrix 监控地址http://cos6743:9000/hystrix
主界面中输入http://cos6743:8081/hystrix.stream或http://cos6743:8082/hystrix.stream
但需要模拟调用接口,否则一直是loading