pom.xml配置
<dependencies>
<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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
- 主启动类添加注解 @EnableHystrixDashboard
- 服务熔断的微服务 必须导入 actuator
- 并在服务熔断的微服务 主启动类配置
public static void main(String[] args) {
SpringApplication.run(PaymentHystrix8001.class,args);
}
//主启动类添加代码
/**
* 此配置是为了服务监控而配置,与服务容错本身无关,SpringCloud升级后的坑
* ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",
* 只要在自己的项目里配置上下面的servlet就可以了
*/
@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
- 启动访问,我的端口是9091,
http://localhost:9001/hystrix
-
曲线:用来记录2分钟内流量的相比变化,可通过他们观察导流量的上升和下降趋势