turbine is a tool for aggregating servers to send event stream data. In hystrix monitoring, only a single node can be monitored, and in actual production, they are clusters. Therefore, turbine can be used to monitor the metrics of hystrix in the cluster, and hystrix services can be discovered through eureka.
Create a new turbine project
TurbineApplication.java
package turbine;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.hystrix.EnableHystrix;import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;import org.springframework.cloud.netflix.turbine.EnableTurbine;/** * Created by sai.luo on 2017/4/26. */@SpringBootApplication@EnableTurbine@EnableHystrix@EnableHystrixDashboardpublic class TurbineApplication{ public static void main(String[] args) { SpringApplication.run(TurbineApplication.class,args); }}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> <artifactId>turbine</artifactId> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <!-- hystrix dependencies--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> </dependency> <!-- turnbine dependencies--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine</artifactId> </dependency> </dependency> </dependency> <dependencyManagement> <dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependency> </dependency> </dependency> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>
application.yml
spring: application: name: turbinesserver: port: 8000turbine: app-config: hello,helloClient ##Service name that needs to be monitored aggregator: clusterConfig: main ##Service cluster name that needs to be monitored clusterNameExpression: metadata['cluster']eureka: instance: preferIpAddress: true statusPageUrlPath: /info.html client: serviceUrl: defaultZone: http://localhost:8761/eureka/
Start the service
helloserviceeureka project application.yml adds cluster configuration
Change to
spring: application: name: helloserver: port: 9001eureka: instance: lease-renewal-interval-in-seconds: 3 lease-expiration-duration-in-seconds: 5 metadata-map: cluster: main client: serviceUrl: defaultZone: http://localhost:8761/eureka/ registry-fetch-interval-seconds: 3logging: level: com: netflix: eureka: OFF discovery: OFF
pom.xml adds hystrix dependency package
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId></dependency>
Similarly, ribboneureka project application.yml adds cluster configuration
After the change, the following
spring: application: name: helloClientserver: port: 20000eureka: instance: lease-renewal-interval-in-seconds: 3 lease-expiration-duration-in-seconds: 5 metadata-map: cluster: main client: serviceUrl: defaultZone: http://localhost:8761/eureka/ registry-fetch-interval-seconds: 3logging: level: com: netflix: eureka: OFF discovery: OFF
pom.xml adds hystrix dependency package
RibbonEurekaApplication.java Add annotation
@EnableHystrix
Start the project
Visit localhost:8000/hystrixx to see the page
Note: Turbine can only monitor the hystrix service, not the hystrix service, and cannot monitor it. For example, although the hello service is configured with a cluster, it does not use hystrix, so it will not be monitored.
Project address https://github.com/luosai001/Spring-Cloud-Sample/tree/master
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.