在 Spring Cloud 应用篇 之 Hystrix Turbine(断路器聚合监控)的基本搭建 这篇文章中,讲解了 Spring Cloud Hystrix Turbine 集群监控服务,但是,如果被监控的服务配置了 context-path 这个属性,那么,你的监控就会出现问题,就如同 Spring Boot Admin 监控出现的问题一样,关于 Spring Boot Admin 的这个问题,可以看一下这篇文章:解决 Spring Cloud 的服务应用配置 context-path 后 Spring Boot Admin 监控不到信息的问题。言归正传,下面我们接着分析服务配置了 context-path 后 Hystrix Turbine 聚合监控不到的问题。
(一)被监控的服务都配置了 context-path 属性
拿之前文章里写的服务 spring-demo-service-feign 做例子
spring-demo-service-feign 的配置文件,添加 context-path 的配置如下:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
# 如果项目配置有 server.servlet.context-path 属性,想要被 spring boot admin 监控,就要配置以下属性
instance:
metadata-map:
management:
context-path: /gateway/actuator
# 解决配置了 context-path 后 spring boot admin 监控第一种方案
# health-check-url: http://localhost:${server.port}/gateway/actuator/health
# status-page-url: http://localhost:${server.port}/gateway/actuator/info
# home-page-url: http://localhost:${server.port}/
# 解决配置了 context-path 后 spring boot admin 监控的第二种方案(优化)
health-check-url-path: /gateway/actuator/health
server:
port: 8382
servlet:
context-path: /gateway
spring:
application:
name: spring-demo-service-feign
feign:
hystrix:
enabled: true
# Ribbon 的负载均衡策略
spring-demo-service:
ribbon:
NFLoadBalancerRuleClassName: com.netflix.loadbalancer.BestAvailableRule
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS
info:
version: 1.0.0
启动 eureka server、spring-demo-service、spring-demo-service-feign、spring-cloud-hystrix-dashboard-turbine 服务
访问 http://localhost:8581/hystrix,输入 http://localhost:8581/turbine.stream,点击 Monitor Stream,发现界面一直是 Loading...状态,之前说过这个可能是因为没有请求数据,那么我们就访问一下接口
访问 http://localhost:8382/gateway/hello
接口已访问,为了证明此时已经有