博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springcloud(第五篇)springcloud turbine
阅读量:6860 次
发布时间:2019-06-26

本文共 7353 字,大约阅读时间需要 24 分钟。

hot3.png

springcloud(第五篇)springcloud turbine 博客分类: 架构 java spring 微服务  

spring cloud turbine

简介

turbine是聚合服务器发送事件流数据的一个工具,hystrix的监控中,只能监控单个节点,实际生产中都为集群,因此可以通过 

turbine来监控集群下hystrix的metrics情况,通过eureka来发现hystrix服务。

netflix turbine

使用官方给定的 

放入tomcat中运行,修改turbine-web-1.0.0/WEB-INF/classesconfig.properties文件

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

turbine.aggregator.clusterConfig 配置集群名称

turbine.ConfigPropertyBasedDiscovery.test.instances 配置集群节点ip(用以发现服务,规则不限在ip列表)

turbine.instanceUrlSuffix 聚合实例访问后缀

重启tomcat后访问{port}/turbine.stream?cluster=test 获取聚合信息

spring cloud turbine

通过EnableTurbine注解启用turbine,需要引入依赖:

org.springframework.cloud
spring-cloud-netflix-turbine
  • 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;/** * 创建turbine应用 * Created by liaokailin on 16/5/1. */@SpringBootApplication@EnableTurbinepublic 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

对应配置信息

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

turbine.appConfig 配置需要聚合的应用 

turbine.aggregator.clusterConfig turbine需要聚合的集群名称 通过  访问 
turbine.clusterNameExpression 获取集群名表达式,这里表示获取元数据中的cluster数据,在node01、node02为配置对应信息

eureka服务

通过eureka做服务发现与注册

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@EnableEurekaServerpublic 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

对应配置信息 表明为一个独立的eureka服务

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

Node

需要创建两个节点组成集群,同时向eureka注册服务

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@RestControllerpublic 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调用hystrix command,对应配置

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@RestControllerpublic 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= 8082spring.application.name=node02eureka.instance.hostname=maceureka.instance.metadata-map.cluster=MAIN
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

两个节点中eureka.instance.hostname不同 

查看 cat /etc/hosts

127.0.0.1       mac127.0.0.1   localhost255.255.255.255 broadcasthost::1             localhost
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

实质指向都为127.0.0.1

这是由于turbine自身的一个bug,eureka.instance.hostname一致时只能检测到一个节点,因此修改hosts,如果是在不同机器演示时不会出现这样的情况

note 节点默认向http://localhost:8761/eureka/apps注册,不需要单独配置

运行

将所有的应用都启动起来,访问http://localhost:8761/ 可以发现注册服务 

eureka server list

http://localhost:8080/hystrix-dashboard-1.4.10/中输入http://localhost:9090/turbine.stream?cluster=MAIN 得到监控界面;

访问http://localhost:8081/ http://localhost:8082/ 观察dashboard的变化 

turbine dashboard

ok ~ it’s work ! more about is 

 

http://blog.csdn.net/liaokailin/article/details/51344281

转载于:https://my.oschina.net/xiaominmin/blog/1599683

你可能感兴趣的文章
Thinking in UML-1-为什么需要UML
查看>>
vs编译obj给delphi用
查看>>
过游戏保护NP或TP的几种方法和思路
查看>>
equals和hashcode为什么要一起重写
查看>>
模态与非模态对话框的问题
查看>>
地对地导弹地对地导弹地对地导弹
查看>>
让div 充满整个body
查看>>
程序员保持快乐活跃的6个好习惯(转)
查看>>
找工作的一些感悟——前端小菜的成长
查看>>
jSON Call can throw but it is not marked with try
查看>>
用过的一些服务器集成软件
查看>>
一键拨打
查看>>
20120522:ERROR - ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
查看>>
Maven构建war项目添加版本号
查看>>
更新 手淘 flexible 布局 rem 单位适配问题
查看>>
新浪微博登录接口实例
查看>>
解析ActionResult子类JsonResult
查看>>
Javascript图片裁切
查看>>
Android -- Serializable和Parcelable需要注意的
查看>>
Apache -- phpmyadmin导入文件过大
查看>>