<!-- 1,使用 Hystrix的模块 hystrix-metrics-event-stream,就可将这些监控的指标信息以
text/event-stream的格式暴露给外部系统。 spring-cloud-starter-netflix-hystrix包含该
模块,在此基础上,只须为项目添加 spring-boot-starter-actuator依赖,就可使
用/hystrix.stream端点获得Hystrix的监控信息了。
2, Feign项目的Hystrix监控
-->
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency>
<!-- 健康度jar-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 虽然Feign已经依赖Hystrix-core 但是想要监控还是不够的 要引入整个Hystrix-->
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
1 package com.tuling.cloud.study; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 import org.springframework.cloud.netflix.feign.EnableFeignClients; 8 9 @EnableDiscoveryClient 10 @SpringBootApplication 11 @EnableFeignClients 12 @EnableCircuitBreaker //这样就可以使用/hystrix.stream端点监控Hystrix了 13 public class ConsumerOrderApplication_07_stream { 14 15 public static void main(String[] args) { 16 SpringApplication.run(ConsumerOrderApplication_07_stream.class, args); 17 } 18 19 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <groupId>com.tuling.cloud</groupId> 6 <artifactId>microservice-hystrix-dashboard</artifactId> 7 <version>0.0.1-SNAPSHOT</version> 8 <packaging>jar</packaging> 9 <name>07-ms-hystrix-dashboard</name> 10 11 <!-- 引入spring boot的依赖 --> 12 <parent> 13 <groupId>org.springframework.boot</groupId> 14 <artifactId>spring-boot-starter-parent</artifactId> 15 <version>1.5.9.RELEASE</version> 16 </parent> 17 18 <properties> 19 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 20 <java.version>1.8</java.version> 21 </properties> 22 23 <dependencies>
<!-- dashBoard包--> 24 <dependency> 25 <groupId>org.springframework.cloud</groupId> 26 <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> 27 </dependency> 28 </dependencies> 29 30 <!-- 引入spring cloud的依赖 --> 31 <dependencyManagement> 32 <dependencies> 33 <dependency> 34 <groupId>org.springframework.cloud</groupId> 35 <artifactId>spring-cloud-dependencies</artifactId> 36 <version>Edgware.RELEASE</version> 37 <type>pom</type> 38 <scope>import</scope> 39 </dependency> 40 </dependencies> 41 </dependencyManagement> 42 43 <!-- 添加spring-boot的maven插件 --> 44 <build> 45 <plugins> 46 <plugin> 47 <groupId>org.springframework.boot</groupId> 48 <artifactId>spring-boot-maven-plugin</artifactId> 49 </plugin> 50 </plugins> 51 </build> 52 </project>
1 package com.jiagoushi.cloud.study; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 6 7 @SpringBootApplication 8 @EnableHystrixDashboard //DashBoard 支持 9 public class HystrixDashboardApplication { 10 11 public static void main(String[] args) { 12 SpringApplication.run(HystrixDashboardApplication.class, args); 13 } 14 }
server: port: 8030
在复杂的分布式系统中,相同服务的节点经常需要部署上百甚至上千个,很多时候,运维人员希望能够把相同服务的节点状态以一个整体集群的形式展现出来,这样可以更好的把握整个系统的状态。 为此,Netflix提供了一个开源项目(Turbine)
来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <groupId>com.tuling.cloud</groupId> 6 <artifactId>microservice-hystrix-turbine</artifactId> 7 <version>0.0.1-SNAPSHOT</version> 8 <packaging>jar</packaging> 9 <name>07-ms-hystrix-turbine</name> 10 11 <!-- 引入spring boot的依赖 --> 12 <parent> 13 <groupId>org.springframework.boot</groupId> 14 <artifactId>spring-boot-starter-parent</artifactId> 15 <version>1.5.9.RELEASE</version> 16 </parent> 17 18 <properties> 19 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 20 <java.version>1.8</java.version> 21 </properties> 22 23 <dependencies> 24 <!-- turbine 依赖--> 25 <dependency> 26 <groupId>org.springframework.cloud</groupId> 27 <artifactId>spring-cloud-starter-netflix-turbine</artifactId> 28 </dependency> 29 </dependencies> 30 31 <!-- 引入spring cloud的依赖 --> 32 <dependencyManagement> 33 <dependencies> 34 <dependency> 35 <groupId>org.springframework.cloud</groupId> 36 <artifactId>spring-cloud-dependencies</artifactId> 37 <version>Edgware.RELEASE</version> 38 <type>pom</type> 39 <scope>import</scope> 40 </dependency> 41 </dependencies> 42 </dependencyManagement> 43 44 <!-- 添加spring-boot的maven插件 --> 45 <build> 46 <plugins> 47 <plugin> 48 <groupId>org.springframework.boot</groupId> 49 <artifactId>spring-boot-maven-plugin</artifactId> 50 </plugin> 51 </plugins> 52 </build> 53 </project>
1 server: 2 port: 8031 3 spring: 4 application: 5 name: microservice-hystrix-turbine 6 eureka: 7 client: 8 service-url: 9 defaultZone: http://localhost:8761/eureka/ 10 instance: 11 prefer-ip-address: true 12 13 #turbine 配置 14 turbine: 15 appConfig: microservice-consumer-order,microservice-consumer-order-feign-hystrix-fallback-stream #微服务名称 16 clusterNameExpression: "‘default‘" 17 18 19
package com.jiagoushi.cloud.study; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.turbine.EnableTurbine; @SpringBootApplication @EnableTurbine //开启turbine public class TurbineApplication { public static void main(String[] args) { SpringApplication.run(TurbineApplication.class, args); } }
欢迎来群592495675一起学习
原文:https://www.cnblogs.com/smallFishs/p/10703566.html