Spring Cloud【Finchley】-11Feign项目整合Hystrix监控

版权声明:【show me the code ,change the world】 https://blog.csdn.net/yangshangwei/article/details/85270935

概述

我们前面的文章 Spring Cloud【Finchley】-09Feign使用Hystrix 中介绍了,如何在使用Feign的项目中使用Hystrix, 现在来探讨下如何在使用Feign的项目中监控Hystrix.


整合步骤

我们知道Hystrix的hystrix-metrics-event-stream模块 将监控信息以text/event-stream的格式暴露给外部系统。

根据spring cloud的套路来讲,一般都是 添加starter依赖,增加注解,使用

我们在原有工程中的依赖也没有找到hystrix-metrics-event-stream该依赖
在这里插入图片描述

所以步骤一就是添加starter依赖

Step1.添加 spring-cloud-starter-netflix-hystrix

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

Step2. 启动类增加@EnableCircuitBreaker或者@EnableHystrix注解

在这里插入图片描述

Step3. 引入spring-boot-starter-actuator并开启端点

spring-boot-starter-actuator是必不可少的

application.yml中开启端点

#actuator  启用所有的监控端点 “*”号代表启用所有的监控端点,可以单独启用,例如,health,info,metrics
#  spring boot 升为 2.0 后,为了安全,默认 Actuator 只暴露了2个端点,heath 和 info,继续
# 访问  http://192.168.1.103:7901/actuator/metrics
management:
  endpoints:
    web:
      exposure:
        include: "*" 
  endpoint:
      health:
        show-details: ALWAYS

在这里插入图片描述

扫描二维码关注公众号,回复: 4664128 查看本文章

Step4. 测试

  1. 启动microservice-discovery-eureka,注册中心
  2. 启动micorservice-provider-user,服务提供者
  3. 启动micorservice-consumer-movie-feign-hystrix
  4. 访问 http://localhost:7901/actuator/hystrix.stream ,如下

在这里插入图片描述

  1. 访问下 http://localhost:7901/movie/3 触发hystrix收集信息
  2. 重新观察 http://localhost:7901/actuator/hystrix.stream
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/yangshangwei/article/details/85270935