15、Feign整合断路器监控Hystrix Dashboard

简介: 本篇讲解一下Feign如何整合断路器监控Hystrix Dashboard。本篇主要整合sc-eureka-client-consumer-feign-hystrix项目和sc-hystrix-dashboard项目。

Ribbon可以整合整合断路器监控Hystrix DashboardFeign也不能少, 本篇讲解一下Feign如何整合断路器监控Hystrix Dashboard。本篇主要整合sc-eureka-client-consumer-feign-hystrix项目和sc-hystrix-dashboard项目。

 

1、 新建项目sc-feign-hystrix-dashboard,对应的pom.xml文件如下


<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>
  <groupId>spring-cloud</groupId>
  <artifactId>sc-feign-hystrix-dashboard</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>sc-feign-hystrix-dashboard</name>
  <url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- 说明是一个 eureka client -->
<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.cloud</groupId>
        <artifactId>spring-cloud-starter-feign</artifactId>
    <version>1.4.5.RELEASE</version>
   </dependency> -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    <version>1.4.5.RELEASE</version>
</dependency> -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
    <version>1.4.5.RELEASE</version>
</dependency> -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
</project>


说明:可以看出这个pom.xml文件是sc-eureka-client-consumer-feign-hystrix项目和sc-hystrix-dashboard项目的并集。

 

2、 新建spring root 启动类FeignDashboardApplication.java


package sc.consumer;
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;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableHystrixDashboard
public class FeignDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(FeignDashboardApplication.class, args);
}
}


这个启动类的注解是sc-eureka-client-consumer-feign-hystrix项目和sc-hystrix-dashboard项目的并集


3、 其他项目文件说明如下,具体见源码


微信图片_20220501181720.png


4、 启动注册中心sc-eureka-server和服务提供者sc-eureka-client-provider,并确保启动成功



5、 启动sc-feign-hystrix-dashboard项目,并验证是否启动成功


方式一:访问注册中心查看sc-feign-hystrix-dashboard项目配置的服务名是否注册成功


微信图片_20220501181727.png

 

方式二:访问仪表盘Dashboard对的地址http://127.0.0.1:5800/hystrix


微信图片_20220501181733.png


6、 使用Hystrix Dashboard查看服务情况


在下图标注处输入http://127.0.0.1:5800/hystrix.stream


微信图片_20220501181738.png


然后点击Monitor Stream按钮


微信图片_20220501181741.png


7、 使用postman访问任意服务接口,以访问获取用户信息接口为例


http://127.0.0.1:5800/feign/user/getUser/3


微信图片_20220501181746.png


尽量多访问几次,然后查看仪表盘Bashboard监控后台,发现之前一直处于Loading的界面发生了变化,如下图,图中单元具体含义可以访问网站


https://github.com/Netflix-Skunkworks/hystrix-dashboard/wiki

 

微信图片_20220501181751.png


访问http://127.0.0.1:5800/hystrix.stream也出现大量数据,这些数据就是对服务的监控数据。


微信图片_20220501181755.png


相关文章
|
6月前
|
Cloud Native Go 微服务
golang 微服务中的断路器 hystrix
golang 微服务中的断路器 hystrix
|
2月前
|
监控 微服务
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
18 0
|
5月前
|
监控 负载均衡 数据可视化
SpringCloud - Hystrix断路器-服务熔断与降级和HystrixDashboard
SpringCloud - Hystrix断路器-服务熔断与降级和HystrixDashboard
29 0
|
6月前
|
Cloud Native 测试技术 Go
golang 微服务中的断路器 hystrix 小案例
golang 微服务中的断路器 hystrix 小案例
|
7月前
|
监控 Java 微服务
16SpringCloud - 断路器项目示例(Hystrix Dashboard)
16SpringCloud - 断路器项目示例(Hystrix Dashboard)
25 0
|
7月前
|
Java Spring
15SpringCloud - 断路器项目示例(Feign Hystrix)
15SpringCloud - 断路器项目示例(Feign Hystrix)
19 0
|
7月前
|
监控 Java
14SpringCloud - 断路器项目示例(Ribbon Hystrix)
14SpringCloud - 断路器项目示例(Ribbon Hystrix)
23 0
|
6月前
|
缓存 运维 监控
微服务技术系列教程(22) - SpringCloud- 服务保护机制Hystrix
微服务技术系列教程(22) - SpringCloud- 服务保护机制Hystrix
60 0
|
7月前
|
缓存 监控 Java
12SpringCloud - 断路器(Hystrix)引入
12SpringCloud - 断路器(Hystrix)引入
29 0
|
7月前
|
Java 微服务 Spring
Spring Cloud Hystrix简单实用
Spring Cloud Hystrix简单实用
61 0