spring cloud turbine
简介
turbine
是聚合服务器发送事件流数据的一个工具,hystrix的监控中,只能监控单个节点,实际生产中都为集群,因此可以通过
turbine来监控集群下hystrix的metrics情况,通过eureka来发现hystrix服务。
netflix turbine
使用官方给定的war
放入tomcat中运行,修改turbine-web-1.0.0/WEB-INF/classes
下config.properties
文件
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
turbine.aggregator.clusterConfig
配置集群名称
turbine.ConfigPropertyBasedDiscovery.test.instances
配置集群节点ip(用以发现服务,规则不限在ip列表)
turbine.instanceUrlSuffix
聚合实例访问后缀
重启tomcat后访问http://localhost:${port}/turbine.stream?cluster=test 获取聚合信息
spring cloud turbine
通过EnableTurbine
注解启用turbine,需要引入依赖:
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
Application.Java
- 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
对应配置信息
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
turbine.appConfig
配置需要聚合的应用
turbine.aggregator.clusterConfig
turbine需要聚合的集群名称 通过 http://localhost:9090/turbine.stream?cluster=MAIN 访问
turbine.clusterNameExpression
获取集群名表达式,这里表示获取元数据中的cluster数据,在node01、node02为配置对应信息
eureka服务
通过eureka
做服务发现与注册
EurekaServer.java
- 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服务
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
Node
需要创建两个节点组成集群,同时向eureka注册服务
Node01.java
- 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
- 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
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
两个节点中eureka.instance.hostname
不同
查看 cat /etc/hosts
- 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/
可以发现注册服务
在http://localhost:8080/hystrix-dashboard-1.4.10/
中输入http://localhost:9090/turbine.stream?cluster=MAIN
得到监控界面;
访问http://localhost:8081/
http://localhost:8082/
观察dashboard的变化
ok ~ it’s work ! more about is here