简介
- 在使用hystrix dashboard组件进行监控服务的熔断情况时,每个服务都有一个hystrix dashboard主页,服务很多时,监控很不方便
- turbine用于聚合多个hystrix dashboard,将多个hystrix dashboard组件的数据放在一个页面进行显示,进行集中监控
集成turbine
- 在前面六篇的基础上在新建一个服务,命名为eureka-monitor-client
对应的文件说明
pom.xml
- 添加 spring-cloud-starter-netflix-turbine、spring-cloud-starter-hystrix-dashboard、spring-cloud-starter-netflix-eureka-client三个依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>eureka-master</artifactId>
<groupId>com.qgg</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eureka-monitor-client</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
</project>
application.yml配置文件
spring:
application:
name: service-turbine
server:
port: 8768
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
turbine:
instanceUrlSuffix: /hystrix.stream # instanceUrlSuffix 访问前缀默认为/actuator/hystrix.stream
aggregator:
cluster-config: default # 指定聚合哪些集群,多个使用","分割,默认为default
app-config: eureka-ribbon-client-1,eureka-feign-client # 配置监控服务的列表,表明监控哪些服务多个使用","分割
#or
cluster-name-expression: new String("default") # 集群名称默认为服务名的集群,当服务数量非常多的时候,可以启动多个
combine-host-port: true
# turbine.combine-host-port参数设置为true,可以让同一主机上的服务通过主机名与端口号的组合来进行区分,默认情况下会以host来区分不同的服务,这会使得在本机调试的时候,本机上的不同服务聚合成一个服务来统计。
启动文件
@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableTurbine // 要启用Turbine,我们只需使用@EnableTurbine对主类进行注释
public class MonitorClientApplication {
public static void main(String[] args) {
SpringApplication.run(MonitorClientApplication.class, args);
}
}
页面访问
-
先启动服务端再启动客户端,客户端启动顺序没要求,访问http://localhost:8761 服务注册中心
-
访问 http://localhost:8768/turbine.stream?cluster=default,如果没有对应的输出,先访问对应的hystrix的接口,如 http://localhost:8767/myFeign/getPort/feign测试
-
仪表盘显示操作,访问 http://localhost:8768/hystrix,填写对应的链接和信息
遇到的问题
- 之前访问 http://localhost:8768/turbine.stream?cluster=default一直没有信息输出,一直打印ping…,并且仪表盘显示loading…,百度了很多文章,也查看了官网的demo,有版本问题,有配置问题,各种问题都会导致以上两个问题的出现,最后在 https://www.jianshu.com/p/590bad4c8947 博主查看到 在yml配置文件中,添加
解决了困扰半天的问题