欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Hystrix?Dashboard斷路監(jiān)控儀表盤的實現(xiàn)詳細介紹

 更新時間:2022年09月01日 11:38:44   作者:悠然予夏  
這篇文章主要介紹了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ù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 在Java編程中使用正則表達式的基本方法

    在Java編程中使用正則表達式的基本方法

    這篇文章主要介紹了在Java編程中使用正則表達式的基本方法,是Java入門學習中的基礎知識,需要的朋友可以參考下
    2015-11-11
  • java lambda表達式用法總結

    java lambda表達式用法總結

    這篇文章主要介紹了java lamda表達式用法總結,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-10-10
  • C++/java 繼承類的多態(tài)詳解及實例代碼

    C++/java 繼承類的多態(tài)詳解及實例代碼

    這篇文章主要介紹了C++/java 繼承類的多態(tài)詳解及實例代碼的相關資料,需要的朋友可以參考下
    2017-02-02
  • Mybatis foreach標簽使用不當導致異常的原因淺析

    Mybatis foreach標簽使用不當導致異常的原因淺析

    這篇文章主要介紹了Mybatis foreach標簽使用不當導致異常的原因探究,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-12-12
  • Java自然排序Comparable使用方法解析

    Java自然排序Comparable使用方法解析

    這篇文章主要介紹了Java自然排序Comparable使用方法解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-04-04
  • @Scheduled fixedDelayString 加載properties配置方式

    @Scheduled fixedDelayString 加載properties配置方式

    這篇文章主要介紹了@Scheduled fixedDelayString 加載properties配置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • elasticsearch索引index之Translog數(shù)據(jù)功能分析

    elasticsearch索引index之Translog數(shù)據(jù)功能分析

    這篇文章主要為大家介紹了elasticsearch索引index之Translog數(shù)據(jù)功能分析,主要分析translog的結構及寫入方式,有需要的朋友可以借鑒參考下
    2022-04-04
  • java使用UDP實現(xiàn)多人聊天功能

    java使用UDP實現(xiàn)多人聊天功能

    這篇文章主要為大家詳細介紹了java使用UDP實現(xiàn)多人聊天功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • SpringBoot中使用 RabbitMQ的教程詳解

    SpringBoot中使用 RabbitMQ的教程詳解

    這篇文章主要介紹了SpringBoot中使用 RabbitMQ的教程詳解,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-11-11
  • spring.profiles使用的方法步驟

    spring.profiles使用的方法步驟

    本文主要介紹了spring.profiles使用與spring.profiles.active和spring.profiles.include區(qū)別,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-07-07

最新評論