SpringCloud HystrixDashboard服務(wù)監(jiān)控詳解
hystrixDashboard服務(wù)監(jiān)控
除了隔離依賴服務(wù)的調(diào)用以外,Hystrix還提供了準(zhǔn)實(shí)時(shí)的調(diào)用監(jiān)控(Hystrix Dashboard),Hystrix會(huì)持續(xù)地記錄所有通過Hystrix發(fā)起的請(qǐng)求的執(zhí)行信息,并以統(tǒng)計(jì)報(bào)表和圖形的形式展示給用戶,包括每秒執(zhí)行多少請(qǐng)求多少成功,多少失敗等。Netflix通過hystrix-metrics-event-stream項(xiàng)目實(shí)現(xiàn)了對(duì)以上指標(biāo)的監(jiān)控。Spring Cloud也提供了Hystrix Dashboard的整合,對(duì)監(jiān)控內(nèi)容轉(zhuǎn)化成可視化界面。
1、新建cloud-consumer-hystrix-dashboard9001
儀表盤監(jiān)控模塊
2、修改pom.xml文件引入儀表盤依賴
核心依賴:spring-cloud-starter-netflix-hystrix-dashboard
注意:所有的圖形化展示,都需要引入spring-boot-starter-actuator
依賴,在8001、8002上都需要引入
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>springcloud2022</artifactId> <groupId>com.zcl.springcloud</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>cloud-consumer-hystrix-dashboard9001</artifactId> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
3、添加YAML配置文件
server:
port: 9001
4、建立啟動(dòng)類
必須要加上@EnableHystrixDashboard
注解激活
package com.zcl.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; /** * 描述:儀表盤啟動(dòng)類 */ @SpringBootApplication @EnableHystrixDashboard public class HystrixDashboardMain9001 { public static void main(String[] args) { SpringApplication.run(HystrixDashboardMain9001.class, args); } }
5、啟動(dòng)項(xiàng)目
啟動(dòng)項(xiàng)目測(cè)試:http://localhost:901/hystrix
使用方法:在下面頁(yè)面中輸入需要進(jìn)行監(jiān)控的地址即可
斷路器演示監(jiān)控
監(jiān)控8001注意事項(xiàng)
1、必須要有如下的兩個(gè)依賴
<!--web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2、對(duì)啟動(dòng)類的修改
注意:新版本Hystrix需要在主啟動(dòng)類MainAppHystrix8001中指定監(jiān)控路徑,否則會(huì)出現(xiàn)報(bào)錯(cuò)
package com.zcl.springcloud; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.annotation.Bean; /** * 描述:熔斷限流啟動(dòng)類 */ @SpringBootApplication @EnableEurekaClient @EnableCircuitBreaker public class PaymentHystrixMain8001 { public static void main(String[] args) { SpringApplication.run(PaymentHystrixMain8001.class, args); } /** *此配置是為了服務(wù)監(jiān)控而配置,與服務(wù)容錯(cuò)本身無關(guān),springcloud升級(jí)后的坑 *ServletRegistrationBean因?yàn)閟pringboot的默認(rèn)路徑不是"/hystrix.stream", *只要在自己的項(xiàng)目里配置上下面的servlet就可以了 */ @Bean public ServletRegistrationBean getServlet() { HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; } }
監(jiān)控測(cè)試
啟動(dòng)7001Eureka服務(wù)中心
觀察監(jiān)控窗口
9001監(jiān)控8001
8001地址測(cè)試
先訪問正確地址,再訪問錯(cuò)誤地址,再正確地址,會(huì)發(fā)現(xiàn)圖示斷路器都是慢慢放開的。
http://localhost:8001/payment/circuit/31:正常的訪問
http://localhost:8001/payment/circuit/-31:異常訪問
監(jiān)控狀態(tài)
到此這篇關(guān)于SpringCloud HystrixDashboard服務(wù)監(jiān)控詳解的文章就介紹到這了,更多相關(guān)SpringCloud HystrixDashboard內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java中使用Thread類和Runnable接口實(shí)現(xiàn)多線程的區(qū)別
這篇文章主要介紹了使用Thread類和Runnable接口實(shí)現(xiàn)多線程的區(qū)別,本文給大家介紹了兩種實(shí)現(xiàn)方式的步驟,除了以上兩種多線程實(shí)現(xiàn)方式,還可以使用 Callable 接口實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07Mybatis特殊字符轉(zhuǎn)義查詢實(shí)現(xiàn)
本文主要介紹了Mybatis特殊字符轉(zhuǎn)義查詢實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02java實(shí)現(xiàn)簡(jiǎn)單的俄羅斯方塊
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)簡(jiǎn)單的俄羅斯方塊,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01Spring AI 使用本地 Ollama Embeddings的操作方法
使用 OpenAI 的 Embeddings 接口是有費(fèi)用的,如果想對(duì)大量文檔進(jìn)行測(cè)試,使用本地部署的 Embeddings 就能省去大量的費(fèi)用,所以我們嘗試使用本地的 Ollama Embeddings,這篇文章主要介紹了Spring AI 使用本地 Ollama Embeddings,需要的朋友可以參考下2024-05-05