乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      springcloud(第五篇)springcloud turbine

       WindySky 2017-07-17

      spring cloud turbine

      簡介

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

      netflix turbine

      使用官方給定的war
      放入tomcat中運行,修改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é)點ip(用以發(fā)現(xiàn)服務(wù),規(guī)則不限在ip列表)

      turbine.instanceUrlSuffix 聚合實例訪問后綴

      重啟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

      對應(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 獲取集群名表達式,這里表示獲取元數(shù)據(jù)中的cluster數(shù)據(jù),在node01、node02為配置對應(yīng)信息

      eureka服務(wù)

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

      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

      對應(yīng)配置信息 表明為一個獨立的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

      需要創(chuàng)建兩個節(jié)點組成集群,同時向eureka注冊服務(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,對應(yīng)配置


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

      配置比較簡單,需要注意的有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

      兩個節(jié)點中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

      實質(zhì)指向都為127.0.0.1

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

      note 節(jié)點默認向http://localhost:8761/eureka/apps注冊,不需要單獨配置

      運行

      將所有的應(yīng)用都啟動起來,訪問http://localhost:8761/ 可以發(fā)現(xiàn)注冊服務(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)載請注明
      http://blog.csdn.net/liaokailin/article/details/51344281

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

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

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多