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

简介: 今天的项目主要整合sc-eureka-client-consumer-ribbon-hystrix项目和sc-hystrix-dashboard项目

上一篇只是大概介绍了一下断路器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类就不多说了,项目接口如下


微信图片_20220501180934.png


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


 

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


方式一:http://127.0.0.1:5600/hystrix验证是否启动成功


微信图片_20220501180948.png


方式二:访问http://127.0.0.1:5600/hystrix.stream


微信图片_20220501181001.png

 

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


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


微信图片_20220501181007.png

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


url里输入:http://127.0.0.1:5600/hystrix.streamIP和端口对应服务消费者的IP和端口)


微信图片_20220501181012.png


然后点击Monitor Stream按钮


微信图片_20220501181016.png


7、 使用postman访问任何接口,以获取用户列表为例


http://127.0.0.1:5600/cli/user/listUser),多访问几次在查看对应的监控界面


微信图片_20220501181024.png


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


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


微信图片_20220501181028.png


http://127.0.0.1:5600/hystrix.stream对应的界面也出现了大量数据,这个也是对服务调用监控的数据。


微信图片_20220501181032.png


其他接口也自行测试。










相关文章
|
监控 Java API
Spring cloud Hystrix 、Dashboard、API(zuul)相关报错
Spring cloud Hystrix 、Dashboard、API(zuul)相关报错
256 2
|
Java 微服务 Spring
微服务(九)-Hystrix(断路器)
微服务(九)-Hystrix(断路器)
hystrix.stream dashboard
hystrix.stream dashboard
118 3
|
监控 Dubbo 应用服务中间件
通用快照方案问题之Sentinel与SpringCloud和Dubbo的整合如何解决
通用快照方案问题之Sentinel与SpringCloud和Dubbo的整合如何解决
174 0
|
监控 Cloud Native Java
通用快照方案问题之Hystrix和Ribbon在超时设置上的冲突如何解决
通用快照方案问题之Hystrix和Ribbon在超时设置上的冲突如何解决
222 0
|
Prometheus 监控 数据可视化
通用快照方案问题之Hystrix进行指标监控如何解决
通用快照方案问题之Hystrix进行指标监控如何解决
145 0
|
监控 Java 数据中心
通用快照方案问题之服务雪崩问题如何解决
通用快照方案问题之服务雪崩问题如何解决
119 0
|
监控
springCloud之Hystrix监控
springCloud之Hystrix监控
206 0
Springcloud-ribbon和hystrix配置
Springcloud-ribbon和hystrix配置
152 0
|
监控 微服务
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
144 0