14、Ribbon整合断路器监控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类就不多说了,项目接口如下

 

 

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

 

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

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

 

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

 

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

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

 

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

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

 

然后点击Monitor Stream按钮

 

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

 

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

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

 

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

 

其他接口也自行测试。

猜你喜欢

转载自www.cnblogs.com/happyhuangjinjin/p/12797558.html
今日推荐