一、使用Hystrix Dashboard可视化监控数据
前文讨论了Hystrix的监控,但都需要通过/hystrix.stream端点获得数据再以文字形式展示的。辨识度很低。
接下来我们使用Hystrix Dashboard让数据图形化、可视化。
1、创建项目eureka-client-hystrix-dashboard
2、添加配置,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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springclouddemo</groupId>
<artifactId>eureka-client-hystrix-dashboard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-client-hystrix-dashboard</name>
<description>可视化监控数据</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</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>
3、编写application配置文件
spring.application.name=eureka-client-hystrix-dashboard
server.port=7210
eureka.client.service-url.defaultZone=http://localhost:7000/eureka/
eureka.instance.prefer-ip-address=true
4、为main类添加@EnableHystrixDashboard注解
package com.springclouddemo.eurekaclienthystrixdashboard;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
/**
* @author 何昌杰
*/
@SpringBootApplication
@EnableHystrixDashboard
@EnableEurekaClient
public class EurekaClientHystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientHystrixDashboardApplication.class, args);
}
}
5、启动main类
访问http://localhost:7210/hystrix,可以看到Hystrix Dashboard的首页
在URL栏输入http://localhost:7209/hystrix.stream,随意设置一个title点击Monitor Stream添加一个监控。如下:
刚开始我们添加成功后只能看到Loading,没有具体的数据,放我们调用一次http://localhost:7209/hello/hcj接口后可视化监控页面将会有图形数据产生。
附一张参数解释图: