Springcloud的turbine配置使用

*爱你&永不变心* 提交于 2019-12-19 00:29:20

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

turbine是聚合服务器发送事件流数据的一个工具,hystrix的监控中,只能监控单个节点,实际生产中都为集群,因此可以通过 turbine来监控集群下hystrix的metrics情况,通过eureka来发现hystrix服务。
1、jar包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>

    <artifactId>love-life-turbine</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>love-life-turbine</name>

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

    <properties>
         <start-class>com.love.life.turbine.boot.TurbineApplication</start-class>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>
     <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Brixton.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <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-web</artifactId>
    </dependency>
    <!-- eureka依赖 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </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>
     <!-- turnbine依赖 -->
     <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-turbine</artifactId>
     </dependency>
     
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
 

2、在application.yml配置

---  
spring:
  rabbitmq:
    host: localhost
    port: 5672
    username: zhb
    password: zhb
    virtual-host: cloud-zhb
eureka:
  instance:
    preferIpAddress: true
    statusPageUrlPath: /info.html
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
turbine:
  appConfig: love-origami-domain,cloud-cust-domain,love-life-app
  aggregator:
    clusterConfig: MAIN
  clusterNameExpression: metadata['cluster']

3、启动程序配置

package com.love.life.turbine.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
import org.springframework.context.annotation.Bean;

/**
 * 项目的启动类,指定扫描的包路径
 * @author itw_huomb
 */
@EnableTurbine
@EnableHystrixDashboard
@SpringBootApplication
@EnableEurekaClient
public class TurbineApplication
{

    public static void main(String[] args)
    {
        SpringApplication.run(TurbineApplication.class, args);
    }
}
4、在被监控的服务application.yml中的euraka服务器配置为,红色为增添的内容

eureka:
  instance:
    preferIpAddress: true
    statusPageUrlPath: /info.html
    metadata-map:
      cluster: MAIN

5、打开地址输入

 

7、在各客户端应用的服务端的断路器配置处

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!