Hystrix?Dashboard斷路監(jiān)控儀表盤的實現(xiàn)詳細介紹
正常狀態(tài)是UP,跳閘是?種狀態(tài)CIRCUIT_OPEN,可以通過/health查看,前提是工程中需要引入SpringBoot的actuator(健康監(jiān)控),它提供了很多監(jiān)控所需的接口,可以對應用系統(tǒng)進行配置查看、相關功能統(tǒng)計等。
已經(jīng)統(tǒng)一添加在父工程中
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
如果我們想看到Hystrix相關數(shù)據(jù),比如有多少請求、多少成功、多少失敗、多少降級等,那么引入SpringBoot健康監(jiān)控之后,訪問/actuator/hystrix.stream接口可以獲取到監(jiān)控的文字信息,但是不直觀,所以Hystrix官方還提供了基于圖形化的DashBoard(儀表板)監(jiān)控平 臺。Hystrix儀表板可以顯示每個斷路器(被@HystrixCommand注解的方法)的狀態(tài)。
1)新建一個監(jiān)控服務工程,導入依賴
<?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>lagou-parent</artifactId> <groupId>com.lagou</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>lagou-cloud-hystrix-dashboard-9000</artifactId> <dependencies><!--hystrix--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <!--hystrix 儀表盤--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> </dependencies> <properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> </project>
2)啟動類添加@EnableHystrixDashboard激活儀表盤
package com.lagou.edu; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @SpringBootApplication @EnableHystrixDashboard // 開啟hystrix dashboard public class HystrixDashboardApplication9000 { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication9000.class, args); } }
3) application.yml
server:
port: 9000
Spring:
application:
name: lagou-cloud-hystrix-dashboard
eureka:
client:
serviceUrl: # eureka server的路徑
defaultZone: http://LagouCloudEurekaServerB:8762/eureka,http://LagouCloudEurekaServerA:8761/eureka #把 eureka 集群中的所有 url 都填寫了進來,也可以只寫?臺,因為各個 eureka server 可以同步注冊表
instance:
#使?ip注冊,否則會使?主機名注冊了(此處考慮到對?版本的兼容,新版本經(jīng)過實驗都是ip)
prefer-ip-address: true
#?定義實例顯示格式,加上版本號,便于多版本管理,注意是ip-address,早期版本是ipAddress
instance-id: ${spring.cloud.client.ipaddress}:${spring.application.name}:${server.port}:@project.version@
4)在被監(jiān)測的微服務中注冊監(jiān)控servlet(自動投遞微服務,監(jiān)控數(shù)據(jù)就是來自于這個微服務)
package com.lagou.edu; 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.SpringCloudApplication; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.netflix.hystrix.EnableHystrix; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; @SpringBootApplication @EnableDiscoveryClient // @EnableHystrix // 打開Hystrix功能 @EnableCircuitBreaker // 開啟熔斷器功能(這個與@EnableHystrix的功能相同,只不過它是通用注解) // @SpringCloudApplication // 綜合性注解 @SpringCloudApplication = @SpringBootApplication + @EnableDiscoveryClient + @EnableCircuitBreaker public class AutoDeliverApplication { public static void main(String[] args) { SpringApplication.run(AutoDeliverApplication.class, args); } // 使用RestTemplate模板對象遠程調(diào)用 @Bean @LoadBalanced public RestTemplate gerRestTemplate() { return new RestTemplate(); } /** * 給被監(jiān)控微服務中注冊一個servlet,后期我們就是通過訪問這個servlet來獲取服務的Hystrix監(jiān)控數(shù)據(jù)的 * 前提:被監(jiān)控的微服務,需要引入SpringBoot Actuator的功能 * @return */ @Bean public ServletRegistrationBean getServlet() { HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/actuator/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; } }
被監(jiān)控微服務發(fā)布之后,可以直接訪問監(jiān)控servlet,但是得到的數(shù)據(jù)并不直觀,后期可以結合儀表盤更友好的展示
5)訪問測試http://localhost:9000/hystrix
輸入監(jiān)控的微服務端點地址,展示監(jiān)控的詳細數(shù)據(jù),比如監(jiān)控服務消費者http://localhost:8090/actuator/hystrix.stream
實心圓:
大?。捍碚埱罅髁康拇笮。髁吭酱笄蛟酱箢伾捍碚埱筇幚淼慕】禒顟B(tài),從綠色到紅色遞減,綠色代表健康,紅色就代表很不健康
曲線波動圖:記錄了2分鐘內(nèi)該方法上流量的變化波動圖,判斷流量上升或者下降的趨勢
到此這篇關于Hystrix Dashboard斷路監(jiān)控儀表盤的實現(xiàn)詳細介紹的文章就介紹到這了,更多相關Hystrix Dashboard斷路監(jiān)控內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Mybatis foreach標簽使用不當導致異常的原因淺析
這篇文章主要介紹了Mybatis foreach標簽使用不當導致異常的原因探究,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-12-12@Scheduled fixedDelayString 加載properties配置方式
這篇文章主要介紹了@Scheduled fixedDelayString 加載properties配置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10elasticsearch索引index之Translog數(shù)據(jù)功能分析
這篇文章主要為大家介紹了elasticsearch索引index之Translog數(shù)據(jù)功能分析,主要分析translog的結構及寫入方式,有需要的朋友可以借鑒參考下2022-04-04