SpringCloud2组件之Hystrix Dashboard详解

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Mr_FLM/article/details/94992084

Hystrix Dashboard:

  Spring Cloud提供的一个仪表盘(Dashboard),用于Hystrix进行监控断路的情况,从而让开发者监控可能出现的问题。

1、创建hystrix-dashboard微服务工程

  我们以通过Hystrix实现调用微服务的超时断路(详见SpringCloud2组件之Hystrix详解),在此基础上,使用Hystrix Dashboard进行断路监控。

(1)client-product组件选择

(2)工程目录

(3)application.yml

server:
  #服务端口
  port: 6001
spring:
  application:
    #服务名称
    name: dashboard

(4)HystrixDashboardApplication

package com.ming.dashboard;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableHystrixDashboard  //开启Hystrix Dashboard
public class HystrixDashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardApplication.class, args);
    }
}

2、改造client-product微服务工程

(1)pom.xml中添加Actuator依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

(2)application.yml中添加属性

server:
  #服务端口
  port: 8000
spring:
  #服务名称
  application:
      name: product
eureka:
  client:
    service-url:
      #服务注册地址
      defaultZone: http://localhost:9000/eureka/
management:
  endpoints:
    web:
      exposure:
        #actuator监控对外暴露hystrix.stream端点,默认情况下,只会暴露health和info端点
        include: health, info, hystrix.stream

3、测试工程

  依次点击ServerEurekaApplication、ClientProductApplication、ClientUserApplication、HystrixDashboardApplication,工程都启动成功后。在浏览器地址栏访问 http://localhost:6001/hystrix, 其结果如下:

进行配置页面,结果如下:

页面配置完成后,点击Monitor Stream按钮,结果如下:

重新打开一个窗口,多次在浏览器地址栏刷新访问 http://localhost:8000/testHystrixByRibbon, 返回查看监控页面,其结果如下:

猜你喜欢

转载自blog.csdn.net/Mr_FLM/article/details/94992084
今日推荐