概述
一)在项目中使用Dashboard(仪表盘)
Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。,说白了。就是通过配置Hystrix Dashboard,我们可以通过浏览页面看运行情况
1.在项目中加入坐标
1)Hystrix
2)actutor
3)dashboard
2.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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sxt</groupId>
<artifactId>24-hystrix-threadpool-dashboard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>24-hystrix-threadpool-dashboard</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR2</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</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-actuator</artifactId>
</dependency>
<!-- 使用可视化界面需要添加的坐标-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>
2.启动进行访问
启动类需要添加两个重要的注解
1.@EnableHystrix:开启Hystrix
2.@EnableHystrixDashboard:开启Dashboard
@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
@EnableHystrix //启动Hystrix
@EnableHystrixDashboard //启动可视化数据Dashboard
public class Application
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
/**
* 配置路径映射,获取JSON格式的请求数据
* @return
*/
@Bean
public ServletRegistrationBean hystrixMetricsStreamServlet() {
ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
registration.addUrlMappings("/hystrix.stream");
return registration;
}
}
使用浏览器访问数据
调用的服务之后可以查看到服务请求结果
3.在可视化页面内查看JSON数据
图解图形页面的列表
最后
以上就是灵巧皮卡丘为你收集整理的Hystrix-Dashboard-可视化监控中心的全部内容,希望文章能够帮你解决Hystrix-Dashboard-可视化监控中心所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复