Hystrix?Dashboard斷路監(jiān)控儀表盤的實(shí)現(xiàn)詳細(xì)介紹
正常狀態(tài)是UP,跳閘是?種狀態(tài)CIRCUIT_OPEN,可以通過/health查看,前提是工程中需要引入SpringBoot的actuator(健康監(jiān)控),它提供了很多監(jiān)控所需的接口,可以對應(yīng)用系統(tǒng)進(jìn)行配置查看、相關(guān)功能統(tǒng)計等。
已經(jīng)統(tǒng)一添加在父工程中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>如果我們想看到Hystrix相關(guān)數(shù)據(jù),比如有多少請求、多少成功、多少失敗、多少降級等,那么引入SpringBoot健康監(jiān)控之后,訪問/actuator/hystrix.stream接口可以獲取到監(jiān)控的文字信息,但是不直觀,所以Hystrix官方還提供了基于圖形化的DashBoard(儀表板)監(jiān)控平 臺。Hystrix儀表板可以顯示每個斷路器(被@HystrixCommand注解的方法)的狀態(tài)。


1)新建一個監(jiān)控服務(wù)工程,導(dǎo)入依賴
<?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 都填寫了進(jìn)來,也可以只寫?臺,因?yàn)楦鱾€ eureka server 可以同步注冊表
instance:
#使?ip注冊,否則會使?主機(jī)名注冊了(此處考慮到對?版本的兼容,新版本經(jīng)過實(shí)驗(yàn)都是ip)
prefer-ip-address: true
#?定義實(shí)例顯示格式,加上版本號,便于多版本管理,注意是ip-address,早期版本是ipAddress
instance-id: ${spring.cloud.client.ipaddress}:${spring.application.name}:${server.port}:@project.version@
4)在被監(jiān)測的微服務(wù)中注冊監(jiān)控servlet(自動投遞微服務(wù),監(jiān)控數(shù)據(jù)就是來自于這個微服務(wù))
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模板對象遠(yuǎn)程調(diào)用
@Bean
@LoadBalanced
public RestTemplate gerRestTemplate() {
return new RestTemplate();
}
/**
* 給被監(jiān)控微服務(wù)中注冊一個servlet,后期我們就是通過訪問這個servlet來獲取服務(wù)的Hystrix監(jiān)控數(shù)據(jù)的
* 前提:被監(jiān)控的微服務(wù),需要引入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)控微服務(wù)發(fā)布之后,可以直接訪問監(jiān)控servlet,但是得到的數(shù)據(jù)并不直觀,后期可以結(jié)合儀表盤更友好的展示

5)訪問測試http://localhost:9000/hystrix

輸入監(jiān)控的微服務(wù)端點(diǎn)地址,展示監(jiān)控的詳細(xì)數(shù)據(jù),比如監(jiān)控服務(wù)消費(fèi)者http://localhost:8090/actuator/hystrix.stream

實(shí)心圓:
大小:代表請求流量的大小,流量越大球越大顏色:代表請求處理的健康狀態(tài),從綠色到紅色遞減,綠色代表健康,紅色就代表很不健康
曲線波動圖:記錄了2分鐘內(nèi)該方法上流量的變化波動圖,判斷流量上升或者下降的趨勢
到此這篇關(guān)于Hystrix Dashboard斷路監(jiān)控儀表盤的實(shí)現(xiàn)詳細(xì)介紹的文章就介紹到這了,更多相關(guān)Hystrix Dashboard斷路監(jiān)控內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- SpringCloud-Hystrix-Dashboard客戶端服務(wù)監(jiān)控的實(shí)現(xiàn)方法
- Springcloud hystrix服務(wù)熔斷和dashboard如何實(shí)現(xiàn)
- SpringCloud之熔斷監(jiān)控Hystrix Dashboard的實(shí)現(xiàn)
- springcloud 熔斷監(jiān)控Hystrix Dashboard和Turbine
- SpringCloud Hystrix-Dashboard儀表盤的實(shí)現(xiàn)
- SpringCloud中的斷路器(Hystrix)和斷路器監(jiān)控(Dashboard)
相關(guān)文章
C++/java 繼承類的多態(tài)詳解及實(shí)例代碼
這篇文章主要介紹了C++/java 繼承類的多態(tài)詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2017-02-02
Mybatis foreach標(biāo)簽使用不當(dāng)導(dǎo)致異常的原因淺析
這篇文章主要介紹了Mybatis foreach標(biāo)簽使用不當(dāng)導(dǎo)致異常的原因探究,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-12-12
@Scheduled fixedDelayString 加載properties配置方式
這篇文章主要介紹了@Scheduled fixedDelayString 加載properties配置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10
elasticsearch索引index之Translog數(shù)據(jù)功能分析
這篇文章主要為大家介紹了elasticsearch索引index之Translog數(shù)據(jù)功能分析,主要分析translog的結(jié)構(gòu)及寫入方式,有需要的朋友可以借鑒參考下2022-04-04

