避坑指南(二):hystrix.stream端点404问题

转载请注明作者及出处:

作者:银河架构师

原文链接:https://www.cnblogs.com/luas/p/12166607.html

问题描述

在项目中集成断路器监控的时候,访问/actuator/htstrix.stream经常会遇到404问题,如下图所示:

此问题根本原因就在于此端点压根就没创建,所以,才会报404错误。

分析解决

如何排查呢?具体有以下几点:

actuator依赖

查确认否引入了spring-boot-starter-actuator依赖。另外,spring-boot-starter-actuator、spring-cloud-starter-netflix-hystrix、spring-cloud-starter-netflix-hystrix-dashboard三个依赖,缺一不可。

<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>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

@EnableHystrixDashboard注解

确认启动类是否引入了@EnableHystrixDashboard注解。

@EnableCircuitBreaker注解

确认启动类是否添加了@EnableCircuitBreaker注解。这个是忽略比较多的一项重要原因。

@EnableHystrix

如果项目基于ribbon,确认启动类是否添加了@EnableHystrix注解。

feign开启hystrix

feign.hystrix.enabled是否为true。需要注意的是,此参数不会影响端点创建,只会影响feign的熔断降级功能是否开启。

配置

确认management.endpoints.web.exposure.include包含的有hystrix.stream,或者直接为'*'。此项为最常见的原因,前面都检查过了,都没问题,那就100%是这个原因了。

management:
  endpoints:
    web:
      exposure:
        include: hystrix.stream
management:
  endpoints:
    web:
      exposure:
        include: '*'

最后,如果全部点均排除完毕,配置也正确,那么,启动项目之后,查看控制台,出现如下提示即算成功。

 

明确提示,注册hystrix.stream-actuator-endpoint端点/actuator/hystrix.stream成功

 

刷新/actuator/hystrix.stream端点,已正常出现ping命名获取数据。

 


微信搜索【银河架构师】,发现更多精彩。

技术资料领取方法:关注公众号,回复微服务,领取微服务相关电子书;回复MK精讲,领取MK精讲系列电子书;回复JAVA 进阶,领取JAVA进阶知识相关电子书;回复JAVA面试,领取JAVA面试相关电子书,回复JAVA WEB领取JAVA WEB相关电子书。

原文地址:https://www.cnblogs.com/luas/p/12166607.html