1. 程式人生 > >Spring Cloud【Finchley】-11Feign專案整合Hystrix監控

Spring Cloud【Finchley】-11Feign專案整合Hystrix監控

文章目錄

概述

我們前面的文章 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

在這裡插入圖片描述


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
    在這裡插入圖片描述