1. 程式人生 > >springcloud-eureka叢集-整合hystrix框架-配置監控

springcloud-eureka叢集-整合hystrix框架-配置監控

1、在服務呼叫者(hystrix客戶端)的依賴檔案pom.xml加入檢測依賴

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

啟動專案訪問 http://127.0.0.1:8666/hystrix.stream 


2、建立一個springboot的檢測專案 eureka-hystrix-monitor

pom.xml

<?
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> <groupId>com.boce</groupId>
<artifactId>eureka-hystrix-monitor</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>eureka-hystrix-monitor</name> <description>Demo project for Spring Boot</description> <parent> <groupId>
org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </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> <!-- 非繼承方式引入maven依賴 --> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <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> <!-- hystrix 監控 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- hystrix 監控 --> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

啟動類EurekaHystrixMonitorApplication.java

@SpringBootApplication
@EnableHystrixDashboard // Hystrix 儀表板;/hystrix 檢視儀表盤;在hystrix客戶端應用使用/hystrix.stream監控
public class EurekaHystrixMonitorApplication {

   public static void main(String[] args) {
      SpringApplication.run(EurekaHystrixMonitorApplication.class, args);
}
}

新建application.yml設定下訪問埠

server:
  port: 8777

啟動專案 訪問http://127.0.0.1:8777/hystrix,填入被監控的服務地址,填寫title,點選Monitor Stream



呼叫服務介面http://127.0.0.1:8666/hello



我們再測試下斷路器的狀態,執行之前編寫main方法,請求hello介面20次


斷路器的狀態成功監控