springcloud-hystrix监控dashboard和turbine

Hystrix Dashboard能对Hystrix进行实时监控,以有效的方式显示每个熔断器的运行状况。
从系统的整体运行状况来看,查看单个服务的Hystrix数据不是很有用,Turbine能将多个服务的数据显示到Hystrix Dashboard上。

Hystrix Dashboard

  1. 复制feign-hystrix-consumer项目重命名为hystrix-dashboard

  2. 添加依赖

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</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>
  1. 修改yml
server:
  port: 8800

spring:
  application:
    #服务名称
    name: hystrix-dashboard

eureka:
  client:
  	#是否将自己注册到Eureka服务中
    register-with-eureka: true
    #是否从Eureka服务中获取注册信息
    fetch-registry: true
    #Eureka注册中心的地址,多个注册中心用,隔开
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

feign:
  hystrix:
    #开启熔断器功能
    enabled: true
    
#将/actuator/hystrix.stream作为管理端点开放
management:
  endpoints:
    web:
      exposure:
        include: hystrix.stream
  1. 开启Hystrix Dashboard
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrix
@EnableHystrixDashboard
public class HystrixDashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardApplication.class, args);
    }
}
  1. 测试
    启动eureka-service和hystrix-dashboard项目,
    访问http://localhost:8800/actuator/hystrix.stream,页面会不断的ping。
    在另一个页面访问当前项目的接口http://localhost:8800/test,ping就会有数据了。
    在这里插入图片描述
    然后访问http://localhost:8800/hystrix,会看到以下页面
    在这里插入图片描述
    将http://localhost:8800/actuator/hystrix.stream填写到输入框,点击monitor。会出现以下页面
    在这里插入图片描述
    其实就是将http://localhost:8800/actuator/hystrix.stream里面的ping图形化了

项目路径

Turbine

  1. 在hystrix-dashboard项目中添加一个application-dashboard2.yml文件
    和application.yml文件一样,只是修改一下服务名和端口
server:
  port: 8801

spring:
  application:
    #服务名称
    name: hystrix-dashboard2

eureka:
  client:
    #是否将自己注册到Eureka服务中
    register-with-eureka: true
    #是否从Eureka服务中获取注册信息
    fetch-registry: true
    #Eureka注册中心的地址,多个注册中心用,隔开
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

feign:
  hystrix:
    #开启熔断器功能
    enabled: true

#将/actuator/hystrix.stream作为管理端点开放
management:
  endpoints:
    web:
      exposure:
        include: hystrix.stream

启动hystrix-dashboard服务和hystrix-dashboard2服务

  1. 创建hystrix-dashboard-turbine项目
<?xml version="1.0" encoding="UTF-8"?>

<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">
    <parent>
        <artifactId>springcloud-demo</artifactId>
        <groupId>demo.cloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>hystrix-dashboard-turbine</artifactId>

    <name>hystrix-dashboard-turbine</name>

    <dependencies>
        <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.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </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-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
        </dependency>
    </dependencies>
</project>
  1. 修改application.yml文件
server:
  port: 8802

spring:
  application:
    #服务名称
    name: hystrix-dashboard-turbine

eureka:
  client:
    #是否将自己注册到Eureka服务中
    register-with-eureka: true
    #是否从Eureka服务中获取注册信息
    fetch-registry: true
    #Eureka注册中心的地址,多个注册中心用,隔开
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
      #defaultZone: http://peer1:8761/eureka/, http://peer2:8762/eureka/

turbine:
  #监控的服务名称
  app-config: hystrix-dashboard, hystrix-dashboard2
  #集群名称
  cluster-name-expression: "'default'"
  #指定聚合哪些集群,默认default
  aggregator:
    cluster-config: default
  1. 开启Turbine
@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class HystrixDashboardTurbineApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardTurbineApplication.class, args);
    }
}
  1. 测试
    访问http://localhost:8802/hystrix,输入http://localhost:8802/turbine.stream点击monitor
    在这里插入图片描述
    项目路径

作者博客

作者公众号
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值