(六)spring-cloud入门学习:断路器聚合监控(Hystrix Dashboard Turbine)

看单个的Hystrix Dashboard的数据并没有什么多大的价值,要想看这个系统的Hystrix Dashboard数据就需要用到Hystrix Turbine。Hystrix Turbine将每个服务Hystrix Dashboard数据进行了整合。

大概思路:
通过eureka-client注册到eureka-server,然后通过application.name获取到应用的监控数据,使用turbine进行整合后在Hystrix Dashboard展示。

在eureka_hystrix_dashboard工程进行调整
1. pom.xml在原本基础上增加了spring-cloud-starter-netflix-eureka-client和spring-cloud-starter-netflix-turbine.

<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.kevin</groupId>
  <artifactId>eureka_hystrix_dashboard</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>eureka_hystrix_dashboard</name>
  <url>http://maven.apache.org</url>

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

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
  </parent>

  <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.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <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-turbine</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
  </dependencies>
  <dependencyManagement>
    <dependencies>
        <dependency>
           <groupId>org.springframework.cloud</groupId>
           <artifactId>spring-cloud-dependencies</artifactId>
           <version>Greenwich.SR1</version>
           <type>pom</type>
           <scope>import</scope>
        </dependency>
    </dependencies>
  </dependencyManagement>
</project>

2. application.properties

spring.application.name=eurekaHystrixDashboard
server.port=9203

# 需要监听的应用名
turbine.appConfig=eurekaRibbon,eurekaFeign
turbine.clusterNameExpression=new String("default")
turbine.aggregator.clusterConfig= default

eureka.client.serviceUrl.defaultZone=http://localhost:9101/eureka/

3. Application.java

package com.kevin.eureka_hystrix_dashboard;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
@EnableDiscoveryClient
public class Application {
	
    public static void main( String[] args ) {
    	new SpringApplicationBuilder(Application.class)
    		.web(WebApplicationType.SERVLET).run(args);
    }
}

4. 启动eurekaServer,两个eurekaClient,两个消费者(eurekaRibbon和eurekaFeign),以及监控eurekaHystrixDashboard

1)查看eurekaServer:http://127.0.0.1:9101/
在这里插入图片描述

2)查看HystrixDashboard:http://127.0.0.1:9203/hystrix
在这里插入图片描述
3)输入http://127.0.0.1:9203/turbine.stream查看,分别监控了两个消费端
在这里插入图片描述

备注:刚开始进来如果处于loading,分别访问一下两个消费者的接口http://127.0.0.1:9201/sayHello和http://127.0.0.1:9202/sayHello即可

猜你喜欢

转载自blog.csdn.net/guangcaiwudong/article/details/96978532
今日推荐