欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-09-07 21:28:56
Ribbon可以整合整合断路器监控Hystrix Dashboard,Feign也不能少, 本篇讲解一下Feign如何整合断路器监控Hystrix Dashboard。本篇主要整合sc-eureka-client-consumer-feign-hystrix项目和sc-hystrix-dashboa ......

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、 其他项目文件说明如下,具体见源码

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

 

 

 

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

 

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

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

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

 

 

 

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

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

 

 

6、 使用hystrix dashboard查看服务情况

在下图标注处输入 

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

 

 

然后点击monitor stream按钮

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

 

 

 

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

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

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

 

 

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

https://github.com/netflix-skunkworks/hystrix-dashboard/wiki

 

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

 

 

 

访问也出现大量数据,这些数据就是对服务的监控数据。

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