turbine监控
分为两步,一个是利用http聚合流访问,一种是采用stream的方式聚合。目前有个问题是采用stream访方式聚合cluster集群将会报错,而且也不会生效,不能采用http://127.0.0.1:7001/turbine.stream?cluster=SONG方式访问,当前章节的前提是拥有一个注册中心
采用http聚合流访问
服务端
1.添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
2.配置yml文件
默认配置
turbine:
aggregator:
cluster-config: default
cluster-name-expression: new String("default")
eureka:
client:
serviceUrl:
defaultZone: http://registry:5000/eureka/
集群配置,客户端也需要配置对应的集群参数
turbine:
aggregator:
cluster-config: COMMON,SONG
app-config: song-service,sc
cluster-name-expression: metadata['cluster']
management:
endpoints:
web:
exposure:
include: '*'
eureka:
client:
serviceUrl:
defaultZone: http://registry:5000/eureka/
3.添加注解@EnableTurbine.
注意:配置集群后,http://127.0.0.1:7001/turbine.stream地址无效,必须用http://127.0.0.1:7001/turbine.stream?cluster=SONG访问
客户端
- 添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
2.配置yml文件
To enable the Hystrix metrics stream, include a dependency on spring-boot-starter-actuator and set management.endpoints.web.exposure.include: hystrix.stream.
management:
endpoints:
web:
exposure:
include: hystrix.stream
eureka:
instance:
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port}
prefer-ip-address: true
metadata-map:
cluster: COMMON # 集群参数
client:
service-url:
defaultZone: http://registry:5000/eureka/
3.添加注@EnableHystrix,@EnableDiscoveryClient
Turbine Stream
采用rabbitmq作为中间件,聚合服务。
服务端
1.添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId> <!-- or '*-stream-kafka' -->
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.配置yaml
turbine:
aggregator:
cluster-config: default
cluster-name-expression: new String("default")
eureka:
client:
serviceUrl:
defaultZone: http://registry:5000/eureka/
3.添加注解@EnableTurbineStream