上一篇利用Hystrix Dashboard去监控断路器的Hystrix command,当我们有很多服务的时候,就需要聚合所有服务的Hystrix Dashboard数据了,这就需要Hystrix Turbine了。
Hystrix Turbine
看单个的Hystrix Dashboard的数据并没有什么多大的价值,要想看这个系统的Hystrix Dashboard数据就需要用到Hystrix Turbine。Hystrix Turbine将每个服务HystrixDashboard数据进行整合。Hystrix Turbine的使用非常简单,只需要引入响应的依赖和加上注解和配置就可以了。
第一种方式:通过Http收集聚合
创建一个spring boot项目,命名为david-turbine
pom.xml
<?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"> <modelVersion>4.0.0</modelVersion> <groupId>com.david</groupId> <artifactId>turbine</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>turbine</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Edgware.SR2</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
启动类中使用@EnableTurbine开启Turbine
@EnableTurbine @SpringBootApplication public class TurbineApplication { public static void main(String[] args) { SpringApplication.run(TurbineApplication.class, args); } }
application.yml
spring: application: name: david-turbine server: port: 8769 security: basic: enabled: false turbine: aggregator: cluster-config: default #指定聚合哪些集群,多个使用 , 分割 默认为default app-config: DAVID-EUREKA-CLIENT,DAVID-FEIGN,DAVID-RIBBON #配置Eureka中的serviceId列表,表明监控哪些服务 cluster-name-expression: new String("default") eureka: client: service-url: defaultZone: http://localhost:8761/eureka/
依次启动项目:
在浏览器输入 http://localhost:8769/turbine.stream
打开:http://localhost:8762/hystrix,输入监控流http://localhost:8769/turbine.stream 确定