日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Cloud【Finchley】-10Hystrix监控

發(fā)布時間:2025/3/21 javascript 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Cloud【Finchley】-10Hystrix监控 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

  • 概述
  • 監(jiān)控Hystrix
  • 步驟
    • Step1 添加spring-cloud-starter-netflix-hystrix依賴
    • Step2 添加spring-boot-starter-actuator依賴
    • Step3 application.yml開啟監(jiān)控端點
    • Step4 測試
  • 代碼

概述

Hystrix除了提供容錯外,還提供了功能近乎實時的監(jiān)控。HystrixCommand和HystrixObservableCommand在執(zhí)行時,會生成執(zhí)行結果和運行指標。


監(jiān)控Hystrix

Hystrix的hystrix-metrics-event-stream模塊 將監(jiān)控信息以text/event-stream的格式暴露給外部系統(tǒng)。添加 spring-cloud-starter-netflix-hystrix依賴后,我們看下pom的依賴關系,如下圖,可以知道 spring-cloud-starter-netflix-hystrix已經(jīng)包含了該模塊。

這樣的話,只需要添加spring-boot-starter-actuator即可,就可以使用 /actuator/hystrix.stream端點來獲取Hystrix的監(jiān)控信息了。


步驟

我們用 上一篇 Spring Cloud【Finchley】-08使用Hystrix實現(xiàn)容錯中的示例來演示下如何監(jiān)控Hystrix. 該工程已經(jīng)能夠滿足我們上面說的監(jiān)控Hystrix的條件

Step1 添加spring-cloud-starter-netflix-hystrix依賴

  • spring-cloud-starter-netflix-hystrix(包含了hystrix-metrics-event-stream)

  • Step2 添加spring-boot-starter-actuator依賴

  • spring-boot-starter-actuator

  • Step3 application.yml開啟監(jiān)控端點

  • application.yml 中 配置信息開啟了所有的監(jiān)控端點
  • #actuator 啟用所有的監(jiān)控端點 “*”號代表啟用所有的監(jiān)控端點,可以單獨啟用,例如,health,info,metrics # spring boot 升為 2.0 后,為了安全,默認 Actuator 只暴露了2個端點,heath 和 info,繼續(xù) # 訪問 http://192.168.1.103:7902/actuator/metrics management:endpoints:web:exposure:include: "*" endpoint:health:show-details: ALWAYS

    Step4 測試

  • 啟動microservice-discovery-eureka,注冊中心
  • 啟動micorservice-provider-user,服務提供者
  • 啟動micorservice-consumer-movie-ribbon-hystrix,服務消費者,整合了Hystrix , 端口 7902
  • 訪問 http://localhost:7902/actuator/hystrix.stream ,如下
  • 一直處于ping 請求狀態(tài),是因為micorservice-consumer-movie-ribbon-hystrix中注解了@HystrixCommand的方法還未被執(zhí)行,沒有產(chǎn)生監(jiān)控數(shù)據(jù),

  • 訪問@HystrixCommand注解標注的方法 ,請求 http://localhost:7902/movie/4 ,重新去 http://localhost:7902/actuator/hystrix.stream 觀察下,如下
  • 重復出現(xiàn)類似的內(nèi)容,是因為系統(tǒng)會不斷的刷新以便可以獲取實時的監(jiān)控數(shù)據(jù),包括HystrixCommand的名稱、group名稱、斷路器名稱、錯誤率、錯誤數(shù)等


    代碼

    https://github.com/yangshangwei/SpringCloudMaster/tree/master/micorservice-consumer-movie-ribbon-hystrix

    總結

    以上是生活随笔為你收集整理的Spring Cloud【Finchley】-10Hystrix监控的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。