1四、Ribbon整合斷路器監控Hystrix Dashboard

上一篇只是大概介紹了一下斷路器Hystrix Dashboard監控,如何使用Hystrix Dashboard監控微服務的狀態呢?這篇看看Ribbon如何整合斷路器監控Hystrix Dashboard。今天的項目主要整合sc-eureka-client-consumer-ribbon-hystrix項目和sc-hystrix-dashboard項目java

 

一、 新建項目sc-ribbon-hystrix-dashboard,對應的pom.xml文件git

 

<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>spring-cloud</groupId>

  <artifactId>sc-ribbon-hystrix-dashboard</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>jar</packaging>

 

  <parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>2.0.4.RELEASE</version>

</parent>

 

<dependencyManagement>

<dependencies>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-dependencies</artifactId>

<version>Finchley.RELEASE</version>

<type>pom</type>

<scope>import</scope>

</dependency>

 

</dependencies>

</dependencyManagement>

 

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven.compiler.source>1.8</maven.compiler.source>

<maven.compiler.target>1.8</maven.compiler.target>

</properties>

 

<dependencies>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

</dependency>

 

<!-- <dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-ribbon</artifactId>

    <version>1.4.5.RELEASE</version>

</dependency> -->

 

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>

</dependency>

 

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-web</artifactId>

</dependency>

 

 

<!--

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-hystrix</artifactId>

    <version>1.4.5.RELEASE</version>

</dependency> -->

 

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>

</dependency>

 

<!-- <dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>

    <version>1.4.5.RELEASE</version>

</dependency> -->

 

 

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>

</dependency>

 

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

 

</dependencies>

</project>

 

 

能夠看到這個pom.xml文件是sc-eureka-client-consumer-ribbon-hstrix項目和sc-hystrix-dashboard項目的pom.xml的並集github

 

 

二、 新建spring boot 啓動類HystrixDashboardApplication.javaweb

package sc.consumer;

 

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

import org.springframework.cloud.netflix.hystrix.EnableHystrix;

import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

 

@SpringBootApplication

@EnableEurekaClient

@EnableHystrix

@EnableHystrixDashboard

public class HystrixDashboardApplication {

 

public static void main(String[] args) {

 

SpringApplication.run(HystrixDashboardApplication.class, args);

 

}

 

}

 

能夠看到這個啓動類的註解也是sc-eureka-client-consumer-ribbon-hstrix項目和sc-hystrix-dashboard項目的啓動類的並集spring

 

三、 其餘的java類就很少說了,項目接口以下apache

 

 

 

 

四、 分別啓動配置中心和sc-eureka-server和服務提供者sc-eureka-client-providermaven

 

五、 啓動項目sc-ribbon-hystrix-dashboardide

方式一:http://127.0.0.1:5600/hystrix驗證是否啓動成功spring-boot

 

 

 

方式二:訪問http://127.0.0.1:5600/hystrix.stream微服務

 

 

 

這個是訪問DashboardServletConfig.java這個servlet對應的地址

      上篇說了一下下圖這段英文的大概意思

 

 

 

六、 演示一下單應用模式下的斷路器監控Hystrix Dashboard

url裏輸入:http://127.0.0.1:5600/hystrix.streamIP和端口對應服務消費者的IP和端口)

 

 

 

而後點擊Monitor Stream按鈕

 

 

 

七、 使用postman訪問任何接口,以獲取用戶列表爲例(http://127.0.0.1:5600/cli/user/listUser),多訪問幾回在查看對應的監控界面

 

 

 

發現監控界面的圖出現了動態變化,這個就是對服務調用的監控。圖中相關單元的含義能夠查看:

https://github.com/Netflix-Skunkworks/hystrix-dashboard/wiki

 

 

 

http://127.0.0.1:5600/hystrix.stream對應的界面也出現了大量數據,這個也是對服務調用監控的數據。

 

 

 

其餘接口也自行測試。

相關文章
相關標籤/搜索