简介
hystrix dashboard可以监控微服务间调用情况,当有服务不可达时可以在控制台及时发现;但是只能监控一个微服务,若是要监控多个微服务,可以使用turbine组件;
前置内容:
实战
1、创建《hystrix-dashboard》模块
1.1、pom
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cc.catface</groupId>
<artifactId>simple-eureka</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>hystrix-dashboard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>server-account</name>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
</dependencies>
</project>
1.2、yml
server:
port: 8060
spring:
application:
name: hystrix-dashboard
eureka:
client:
service-url:
defaultZone: http://localhost:7000/eureka/
1.3、application
1、《server-account》的application声明注解@EnableCircuitBreaker
,即将信息分享给监控中心hystrix dashboard;
2、《hystrix-dashboard》的application声明注解@EnableHystrixDashboard
,即开启hystrix dashboard监控器;
2、查看效果
2.1、发起请求
请求http://localhost:7003/testFeign;
2.2、打开控制台观察
打开http://localhost:8060/hystrix,输入http://localhost:7003/actuator/hystrix.stream,点击Monitor Stream;
2.3、不停请求观察控制台
29是请求次数,0.0%表示《server-account》服务正常;
2.4、关闭《server-account》再不停请求观察控制台
100.0%表示《server-account》已不可达;