日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

springcloud(第五篇)springcloud turbine

 WindySky 2017-07-17

spring cloud turbine

簡(jiǎn)介

turbine是聚合服務(wù)器發(fā)送事件流數(shù)據(jù)的一個(gè)工具,hystrix的監(jiān)控中,只能監(jiān)控單個(gè)節(jié)點(diǎn),實(shí)際生產(chǎn)中都為集群,因此可以通過
turbine來監(jiān)控集群下hystrix的metrics情況,通過eureka來發(fā)現(xiàn)hystrix服務(wù)。

netflix turbine

使用官方給定的war
放入tomcat中運(yùn)行,修改turbine-web-1.0.0/WEB-INF/classesconfig.properties文件

turbine.aggregator.clusterConfig=test
turbine.ConfigPropertyBasedDiscovery.test.instances=10.0.80.60,10.0.41.13
turbine.instanceUrlSuffix=:8080/configcenter-web/hystrix.stream
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

turbine.aggregator.clusterConfig 配置集群名稱

turbine.ConfigPropertyBasedDiscovery.test.instances 配置集群節(jié)點(diǎn)ip(用以發(fā)現(xiàn)服務(wù),規(guī)則不限在ip列表)

turbine.instanceUrlSuffix 聚合實(shí)例訪問后綴

重啟tomcat后訪問http://localhost:${port}/turbine.stream?cluster=test 獲取聚合信息

spring cloud turbine

通過EnableTurbine注解啟用turbine,需要引入依賴:

  <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-turbine</artifactId>
        </dependency>
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

Application.Java

package com.lkl.springcloud.turbine;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

/**
 * 創(chuàng)建turbine應(yīng)用
 * Created by liaokailin on 16/5/1.
 */
@SpringBootApplication
@EnableTurbine
public class Application {

    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class).web(true).run(args);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

對(duì)應(yīng)配置信息

server.port=9090
spring.application.name=turbine
turbine.appConfig=node01,node02
turbine.aggregator.clusterConfig= MAIN
turbine.clusterNameExpression= metadata['cluster']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

turbine.appConfig 配置需要聚合的應(yīng)用
turbine.aggregator.clusterConfig turbine需要聚合的集群名稱 通過 http://localhost:9090/turbine.stream?cluster=MAIN 訪問
turbine.clusterNameExpression 獲取集群名表達(dá)式,這里表示獲取元數(shù)據(jù)中的cluster數(shù)據(jù),在node01、node02為配置對(duì)應(yīng)信息

eureka服務(wù)

通過eureka做服務(wù)發(fā)現(xiàn)與注冊(cè)

EurekaServer.java

package com.lkl.springcloud.turbine;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@EnableEurekaServer
public class EurekaServer {

    public static void main(String[] args) {
        new SpringApplicationBuilder(EurekaServer.class).properties(
                "spring.config.name:eureka", "logging.level.com.netflix.discovery:OFF")
                .run(args);
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

對(duì)應(yīng)配置信息 表明為一個(gè)獨(dú)立的eureka服務(wù)

server.port=8761
spring.application.name=eureka
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

Node

需要?jiǎng)?chuàng)建兩個(gè)節(jié)點(diǎn)組成集群,同時(shí)向eureka注冊(cè)服務(wù)

Node01.java

package com.lkl.springcloud.turbine;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by liaokailin on 16/5/4.
 */
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableCircuitBreaker
@RestController
public class Node01 {

    public static void main(String[] args) {
        new SpringApplicationBuilder(Node01.class).properties(
                "spring.config.name:node01").run(args);
    }

    @Autowired
    private HelloService service;

    @RequestMapping("/")
    public String hello() {
        return this.service.hello();
    }


    @Component
    public static class HelloService {

        @HystrixCommand(fallbackMethod="fallback")
        public String hello() {
            return "Hello World";
        }
        public String fallback() {
            return "Fallback";
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

Node01調(diào)用hystrix command,對(duì)應(yīng)配置


server.port= 8081
spring.application.name=node01
eureka.instance.hostname=localhost
eureka.instance.metadata-map.cluster=MAIN

配置比較簡(jiǎn)單,需要注意的有eureka.instance.hostname,把Node02 展示出來再說明eureka.instance.hostname

Node02.java

package com.lkl.springcloud.turbine;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by liaokailin on 16/5/4.
 */
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableCircuitBreaker
@RestController
public class Node02 {

    public static void main(String[] args) {
        new SpringApplicationBuilder(Node02.class).properties(
                "spring.config.name:node02").run(args);
    }

    @Autowired
    private HelloService service;

    @RequestMapping("/")
    public String hello() {
        return this.service.hello();
    }


    @Component
 public static class HelloService {

        @HystrixCommand(fallbackMethod="fallback")
        public String hello() {
            return "Hello World";
        }
        public String fallback() {
            return "Fallback";
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

node02.properties

server.port= 8082
spring.application.name=node02
eureka.instance.hostname=mac
eureka.instance.metadata-map.cluster=MAIN
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

兩個(gè)節(jié)點(diǎn)中eureka.instance.hostname不同
查看 cat /etc/hosts

127.0.0.1       mac
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

實(shí)質(zhì)指向都為127.0.0.1

這是由于turbine自身的一個(gè)bug,eureka.instance.hostname一致時(shí)只能檢測(cè)到一個(gè)節(jié)點(diǎn),因此修改hosts,如果是在不同機(jī)器演示時(shí)不會(huì)出現(xiàn)這樣的情況

note 節(jié)點(diǎn)默認(rèn)向http://localhost:8761/eureka/apps注冊(cè),不需要單獨(dú)配置

運(yùn)行

將所有的應(yīng)用都啟動(dòng)起來,訪問http://localhost:8761/ 可以發(fā)現(xiàn)注冊(cè)服務(wù)
eureka server list

http://localhost:8080/hystrix-dashboard-1.4.10/中輸入http://localhost:9090/turbine.stream?cluster=MAIN 得到監(jiān)控界面;

訪問http://localhost:8081/ http://localhost:8082/ 觀察dashboard的變化
turbine dashboard

ok ~ it’s work ! more about is here

轉(zhuǎn)載請(qǐng)注明
http://blog.csdn.net/liaokailin/article/details/51344281

歡迎關(guān)注,您的肯定是對(duì)我最大的支持

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多