今天在看hystrix断路器监控仪表盘的使用,但发现网上大部分的文章在最新版中都已经不在适用,摸了几个小时,才发现原来是配置造成的(其中还有新版的引入路径也发生了变化 )、
上代码 ,,引入要使用的jar包
<!--仪表板监控依赖 这里引入的路径与老版本的不一样-->
<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>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
在springboot的启动类上加上注解:@EnableHystrixDashboard
@SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
@EnableHystrixDashboard
public class OrderServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication.class, args);
}
}
请注意,以上两步在网上的很多文章中,与此都有不同,这是因为版本的原因造成的。。。
最关键的是第三步,这一步在网上未发现有人贴出来。代码如下 :
#断路器监控仪表盘,主要是因为新版本的默认只开放了个另功能,如果要实现完整的功能,就要将所有功能放开
management.endpoints.web.exposure.include=*
访问路径 :http://localhost:2223/hystrix(注意:这个2223端口是自己定义的server.port=2223),要用自己的,要不然显示不出来。。
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiAzNfRHLGZkRGZkRfJ3bs92YsYTMfVmepNHL9cGVOVnRHFmb1cVYy5kMMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnLwMTOxMDOwgTM4EzMwkTMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
最后一步,我发现好多文章上都是说单体应用的监控路径:通过URL:http://hystrix-app:port/hystrix.stream开启,但实现在新版本并不是这样的,须要加actuator路径 ,我的访问路径如下:
http://localhost:2223/actuator/hystrix.stream
结果:
请注意:如果想显示上面的数据,还要请求一下任意接口才能监控到。。