目錄
Hystrix 的實時監控功能
Hystrix 的實時監控功能
在微服務架構中,Hystrix 除了實作容錯外,還提供了實時監控功能,在服務呼叫時,Hystrix 會實時累積關于 HystrixCommand 的執行資訊,比如每秒的請求數、成功數等,
更多的指標資訊請查看官方檔案:https://github.com/Netflix/Hystrix/wiki/Metrics-and-Monitoring,
Hystrix 監控需要兩個必備條件:
必須有 Actuator 的依賴,代碼如下所示:
<!-- spring actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
必須有 Hystrix 的依賴,Spring Cloud 中必須在啟動類中添加 @EnableHystrix 開啟 Hystrix,代碼如下所示:
<!-- hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
加入依賴后,將 actuator 中的端點暴露出來,訪問端點地址(http://localhost:8091/actuator/hystrix.stream):
management:
endpoints:
web:
exposure:
include: hystrix.stream
第一次看到一直在輸出 ping:,出現這種情況是因為還沒有資料,等到 HystrixCommand 執行了之后就可以看到具體資料了,
呼叫一下 /user/query/1 介面 http://localhost:8091/user/query/1,訪問之后就可以看到 http://localhost:8091/actuator/hystrix.stream 這個頁面中輸出的資料了:
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/265830.html
標籤:其他
上一篇:分布式事務實戰方案匯總
