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

14、Ribbon整合断路器监控Hystrix Dashboard

程序员文章站 2022-06-19 10:15:21
上一篇只是大概介绍了一下断路器Hystrix Dashboard监控,如何使用Hystrix Dashboard监控微服务的状态呢?这篇看看Ribbon如何整合断路器监控Hystrix Dashboard。今天的项目主要整合sc-eureka-client-consumer-ribbon-hystr ......

上一篇只是大概介绍了一下断路器hystrix dashboard监控,如何使用hystrix dashboard监控微服务的状态呢?这篇看看ribbon如何整合断路器监控hystrix dashboard。今天的项目主要整合sc-eureka-client-consumer-ribbon-hystrix项目和sc-hystrix-dashboard项目

 

1、 新建项目sc-ribbon-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-ribbon-hystrix-dashboard</artifactid>

  <version>0.0.1-snapshot</version>

  <packaging>jar</packaging>

 

  <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>

<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-ribbon</artifactid>

    <version>1.4.5.release</version>

</dependency> -->

 

<dependency>

<groupid>org.springframework.cloud</groupid>

<artifactid>spring-cloud-starter-netflix-ribbon</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-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.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.boot</groupid>

    <artifactid>spring-boot-starter-actuator</artifactid>

</dependency>

 

</dependencies>

</project>

 

可以看到这个pom.xml文件是sc-eureka-client-consumer-ribbon-hstrix项目和sc-hystrix-dashboard项目的pom.xml的并集

 

 

2、 新建spring boot 启动类hystrixdashboardapplication.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.enablehystrix;

import org.springframework.cloud.netflix.hystrix.dashboard.enablehystrixdashboard;

 

@springbootapplication

@enableeurekaclient

@enablehystrix

@enablehystrixdashboard

public class hystrixdashboardapplication {

 

public static void main(string[] args) {

 

springapplication.run(hystrixdashboardapplication.class, args);

 

}

 

}

可以看到这个启动类的注解也是sc-eureka-client-consumer-ribbon-hstrix项目和sc-hystrix-dashboard项目的启动类的并集

 

3、 其他的java类就不多说了,项目接口如下

 14、Ribbon整合断路器监控Hystrix Dashboard

 

 

 

4、 分别启动配置中心和sc-eureka-server和服务提供者sc-eureka-client-provider

 

5、 启动项目sc-ribbon-hystrix-dashboard

方式一:验证是否启动成功

 14、Ribbon整合断路器监控Hystrix Dashboard

 

 

方式二:访问

 14、Ribbon整合断路器监控Hystrix Dashboard

 

 

这个是访问dashboardservletconfig.java这个servlet对应的地址

      上篇说了一下下图这段英文的大概意思

 14、Ribbon整合断路器监控Hystrix Dashboard

 

 

6、 演示一下单应用模式下的断路器监控hystrix dashboard

url里输入:ip和端口对应服务消费者的ip和端口)

 14、Ribbon整合断路器监控Hystrix Dashboard

 

 

然后点击monitor stream按钮

 14、Ribbon整合断路器监控Hystrix Dashboard

 

 

7、 使用postman访问任何接口,以获取用户列表为例(http://127.0.0.1:5600/cli/user/listuser),多访问几次在查看对应的监控界面

 14、Ribbon整合断路器监控Hystrix Dashboard

 

 

发现监控界面的图出现了动态变化,这个就是对服务调用的监控。图中相关单元的含义可以查看:

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

 14、Ribbon整合断路器监控Hystrix Dashboard

 

 

对应的界面也出现了大量数据,这个也是对服务调用监控的数据。

 14、Ribbon整合断路器监控Hystrix Dashboard

 

 

其他接口也自行测试。