最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

關于Hystrix的監(jiān)控及可視化面板

 更新時間:2023年08月28日 10:15:48   作者:凝望深藍  
這篇文章主要介紹了關于Hystrix的監(jiān)控及可視化面板,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

Hystrix監(jiān)控

Hystrix除了實現(xiàn)容錯之外,還提供了近乎實時的監(jiān)控。Hystrix Command和HystrixObservableCommand在執(zhí)行時,會會生成執(zhí)行結果和運行指標,比如每秒的請求數(shù)和成功數(shù)等,這些監(jiān)控數(shù)據(jù)對于分析系統(tǒng)請求的調用情況很有用。

我們以之前項目介紹過的micro-service-consumer-ribbon-hystrix為例,因為之前的項目中已經包含了spring-boot-starter-actuator和spring-cloud-starter-hystrix,因此可以直接通過http://localhost:7908/hystrix.stream來訪問,但是頁面展示的并不直觀。

那么為什么之前介紹的micro-service-consumer-movie-feign-hystrix-fallback-factory打開http://localhost:8028/hystrix.stream卻是404呢?因為在引入feign的時候帶了hystrix,因此只需要再單獨引入hystrix即可,同時還需要在啟動類上加@EnableCircuitBreaker。

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>

使用Hystrix Dashboard 數(shù)據(jù)可視化監(jiān)控面板

創(chuàng)建micro-service-hystrix-dashboard項目,首先來看一下這個項目的pom文件,我們引入了spring-cloud-starter-hystrix-dashboard的依賴:

<?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">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>micro-service-hystrix-dashboard</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <parent>
        <groupId>com.fanfan.cloud</groupId>
        <artifactId>micro-service-spring-cloud-study</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
        </dependency>
    </dependencies>
    <!-- 引入spring cloud的依賴 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Edgware.SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <finalName>micro-service-hystrix-dashboard</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

接下來是編寫啟動類,在啟動類上添加@EnableHystrixDashboard注解:

@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {
  public static void main(String[] args) {
    SpringApplication.run(HystrixDashboardApplication.class, args);
  }
}

application.yml的配置文件為:

server:
  port: 8030

由配置可知,我們并沒有把HystrixDashboard注冊到Eureka上。

訪問http://localhost:8030/hystrix,可看到如下的畫面,輸入http://localhost:8028/hystrix.stream地址查看監(jiān)控數(shù)據(jù)。

在這里插入圖片描述

在這里插入圖片描述

我們也可以將dashboard注冊到Eureka:

server:
  port: 8030
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
spring:
  application:
    name: hystrix-dashboard

使用Turbine聚合監(jiān)控數(shù)據(jù)

上面我們使用/hystrix.stream端點監(jiān)控單個微服務實例,然而微服務架構的應用系統(tǒng)一般會有若干個微服務,如果每次只能查看單個實例的監(jiān)控數(shù)據(jù),就要不停地切換Hystrix Dashboard的監(jiān)控地址,非常不便,因此我們引入Hystrix監(jiān)控數(shù)據(jù)聚合工具Turbine,它可以將所有相關的/hystrix.stream端點的數(shù)據(jù)聚合到一個組合的/turbine.stream中,從而使得集群監(jiān)控更加方便。

創(chuàng)建一個項目micro-service-hystrix-turbine,需要引入spring-cloud-starter-turbine的依賴,如下所示:

<?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">
    <!-- 引入spring boot的依賴 -->
    <modelVersion>4.0.0</modelVersion>
    <artifactId>micro-service-hystrix-turbine</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <parent>
        <groupId>com.fanfan.cloud</groupId>
        <artifactId>micro-service-spring-cloud-study</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-turbine</artifactId>
        </dependency>
    </dependencies>
    <!-- 引入spring cloud的依賴 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Edgware.SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <finalName>micro-service-hystrix-turbine</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

在啟動類上添加@EnableTurbine注解,如下所示:

@SpringBootApplication
@EnableTurbine
public class TurbineApplication {
  public static void main(String[] args) {
    SpringApplication.run(TurbineApplication.class, args);
  }
}

接下來是application.yml配置文件:

server:
  port: 8031
spring:
  application:
    name: hystrix-turbine
eureka:
  client:
    serviceUrl:
      defaultZone: http://discovery:8761/eureka/
  instance:
    prefer-ip-address: true
 # 這里的名字是spring.application.name
turbine:
  appConfig: cunsumer-ribbon-custom-hystrix,cunsumer-movie-feign-hystrix-fallback
  clusterNameExpression: "'default'"

接下來我們分別啟動micro-service-discovery-eureka、micro-service-provider-user、micro-service-consumer-ribbon-hystrix、micro-service-consumer-movie-feign-hystrix-fallback、micro-service-hystrix-dashboard、micro-service-hystrix-turbine,然后訪問http://localhost:8030/hystrix, 輸入http://localhost:8031/turbine.stream查看監(jiān)控數(shù)據(jù):

使用消息中間件收集數(shù)據(jù)

在微服務和Turbine網(wǎng)絡不通的情況下,可借助消息中間件進行數(shù)據(jù)收集。

各個微服務將Hystrix Command的監(jiān)控數(shù)據(jù)發(fā)送至消息中間件,Turbine去消費消息中間件的數(shù)據(jù)。

作者書上使用的消息隊列使用RabbitMQ,需要安裝并啟動,先安裝Erlang OTP。

RabbitMQ和 Erlang OTP的下載地址

安裝完成后,在sbin目錄下(或者將sbin目錄配置到環(huán)境變量,然后執(zhí)行 rabbitmq-plugins enable rabbitmq_management 啟動服務

配置完成后,先執(zhí)行stop再執(zhí)行start。

啟動后打開如下的頁面:localhost:15672,用戶名和密碼都是guest。

項目中使用的是rabbitmq,要注意rabbitmq和activemq不可以同時開啟。否則回報錯。

com.rabbitmq.client.MalformedFrameException: AMQP protocol version mismatch; we are version 0-9-1, server sent signature 3,1,0,0

創(chuàng)建消息隊列相關的項目

復制micro-service-consumer-ribbon-hystrix,修改為micro-service-consumer-ribbon-hystrix-turbine-mq項目,pom文件中引入spring-cloud-netflix-hystrix-stream和spring-cloud-starter-stream-rabbit的依賴,如下:

<?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">
	<modelVersion>4.0.0</modelVersion>
	<artifactId>micro-service-consumer-ribbon-hystrix-turbine-mq</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>
	<parent>
		<groupId>com.fanfan.cloud</groupId>
		<artifactId>micro-service-spring-cloud-study</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-netflix-hystrix-stream</artifactId>
		</dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
        </dependency>
	</dependencies>
	<!-- 引入spring cloud的依賴 -->
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Edgware.SR6</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<build>
		<finalName>micro-service-consumer-ribbon-hystrix-turbine-mq</finalName>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

配置文件application.yml文件:

server:
  port: 7910
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
spring:
  application:
    name: cunsumer-ribbon-custom-hystrix
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

以上監(jiān)控數(shù)據(jù)發(fā)送到消息隊列就修改完了。

然后我們創(chuàng)建項目micro-service-hystrix-turbine-mq,需要引入spring-cloud-starter-turbine-stream和spring-cloud-starter-stream-rabbit的依賴,pom文件為:

<?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">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>micro-service-hystrix-turbine-mq</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <parent>
        <groupId>com.fanfan.cloud</groupId>
        <artifactId>micro-service-spring-cloud-study</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-turbine-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
        </dependency>
    </dependencies>
    <build>
        <finalName>micro-service-hystrix-turbine-mq</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

將@EnableTurbine修改為@EnableTurbineStream,修改配置文件application.yml文件:

server:
  port: 8032
spring:
  application:
    name: robot-hystrix-turbine-mq
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
eureka:
  client:
    serviceUrl:
      defaultZone: http://discovery:8761/eureka/
  instance:
    prefer-ip-address: true

總結

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • SpringBoot中使用AOP打印接口日志的方法

    SpringBoot中使用AOP打印接口日志的方法

    本篇文章主要介紹了SpringBoot中使用AOP打印接口日志的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • Java的垃圾強制回收實例分析

    Java的垃圾強制回收實例分析

    這篇文章主要介紹了Java的垃圾強制回收,結合實例形式分析了java垃圾強制回收的相關原理及實現(xiàn)方法,需要的朋友可以參考下
    2019-08-08
  • Spring boot @RequestBody數(shù)據(jù)傳遞過程詳解

    Spring boot @RequestBody數(shù)據(jù)傳遞過程詳解

    這篇文章主要介紹了Spring boot @RequestBody數(shù)據(jù)傳遞過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-12-12
  • 關于postman傳參的幾種格式 list,map 等

    關于postman傳參的幾種格式 list,map 等

    這篇文章主要介紹了postman傳參的幾種格式 list,map等,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java中的ThreadLocal詳解

    Java中的ThreadLocal詳解

    THreadLocalMap中的Entry的key使用的是ThreadLocal對象的弱引用,在沒有其他地方對ThreadLoca依賴,ThreadLocalMap中的ThreadLocal對象就會被回收掉,但是對應的不會被回收,具體內容請和小編一起看下面文章詳情
    2021-09-09
  • Java泛型定義與用法實例詳解

    Java泛型定義與用法實例詳解

    這篇文章主要介紹了Java泛型定義與用法,結合實例形式較為詳細的分析了Java中泛型的概念、原理、定義、使用方法及相關操作注意事項,需要的朋友可以參考下
    2018-08-08
  • java maven進階教學

    java maven進階教學

    這篇文章主要介紹了Maven進階教程的相關資料,文中講解非常細致,幫助大家開始學習maven,感興趣的朋友可以了解下,希望能夠給你帶來幫助
    2021-08-08
  • 帶你快速搞定java IO

    帶你快速搞定java IO

    這篇文章主要介紹了Java IO流 文件傳輸基礎的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下,希望能給你帶來幫助
    2021-07-07
  • Java+opencv3.2.0之直方圖均衡詳解

    Java+opencv3.2.0之直方圖均衡詳解

    這篇文章主要為大家詳細介紹了Java+opencv3.2.0之直方圖均衡的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • MyBatis中批量插入的三個關鍵優(yōu)化技巧與避坑指南

    MyBatis中批量插入的三個關鍵優(yōu)化技巧與避坑指南

    這篇文章主要為大家詳細介紹了MyBatis中批量插入的三個關鍵優(yōu)化技巧與避坑指南,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2026-01-01

最新評論

新龙县| 弋阳县| 民和| 清丰县| 财经| 鄂尔多斯市| 和政县| 海兴县| 缙云县| 资溪县| 松溪县| 南汇区| 肇东市| 大连市| 武城县| 长葛市| 镇安县| 瓮安县| 岢岚县| 重庆市| 虞城县| 宁波市| 华蓥市| 平定县| 清丰县| 金川县| 涞源县| 旌德县| 陕西省| 张掖市| 固始县| 巫山县| 改则县| 临邑县| 汉源县| 曲水县| 胶南市| 鹤壁市| 顺平县| 武川县| 鞍山市|