21、断路器集群监控Turbine

简介: 本文将结合之前学习的注册中心Eureka、服务提供者Provider、断路器Hystrix和仪表盘Dashboard,学习断路器集群监控Turbine。

前几篇已经实现了对单个服务实例的监控,当然在实际应用中,单个实例的监控数据没有多大的价值,我们其实更需要的是一个集群系统的监控信息,这时就需要引入TurbineTurbine能够汇集监控信息,并将聚合后的信息提供给Hystrix Dashboard来集中展示和监控。


      本文将结合之前学习的注册中心Eureka、服务提供者Provider、断路器Hystrix和仪表盘Dashboard,学习断路器集群监控Turbine最终整体架构如下:


微信图片_20220501211246.png

 

 

项目说明:


注册中心:sc-eureka-server


服务提供者:sc-server-turbine-hystrix-dashboard-node1、sc-server-turbine-hystrix-dashboard-node2


服务消费者、断路器:sc-client-turbine-hystrix-dashboard-node1、sc-client-turbine-hystrix-dashboard-node2


集群监控、仪表盘:sc-client-turbine-hystrix

 

1、 注册中心项目sc-eureka-server参考《eureka注册中心单机》



2、 服务提供者项目sc-server-turbine-hystrix-dashboard-node1、sc-server-turbine-hystrix-dashboard-node2由项目sc-eureka-client-provider改造而来。


sc-server-turbine-hystrix-dashboard-node1:


微信图片_20220501211252.png


sc-server-turbine-hystrix-dashboard-node2

 

微信图片_20220501211256.png


3、 服务消费者、断路器项目sc-client-turbine-hystrix-dashboard-node1、sc-client-turbine-hystrix-dashboard-node2由项目sc-feign-hystrix-dashboard改造而来。


sc-client-turbine-hystrix-dashboard-node1


(1) bootstrap.yml修改


server:
  port: 5801


(2) application.yml文件修改


微信图片_20220501211300.png


3)去掉springcloud启动类的EnableHystrixDashboard注解

 

sc-client-turbine-hystrix-dashboard-node2


1bootstrap.yml修改


server:
  port: 5802


2application.yml文件修改


微信图片_20220501211304.png


(3) 去掉springcloud启动类的EnableHystrixDashboard注解

 

注: turbine只能监控Hystrix服务。不是Hystrix的服务不能监控。所以配置文件都配置了如下配置项

 

微信图片_20220501211308.png


4、 新建集群监控、仪表盘项目sc-client-turbine-hystrix,对应的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-client-turbine-hystrix</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sc-client-turbine-hystrix</name>
<url>http://maven.apache.org</url>
  <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-turbine</artifactId>
    <version>1.4.5.RELEASE</version>
</dependency> -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-turbine</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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>


5、 新建配置文件application.yml


spring:
  application:
    name: sc-client-turbine-hystrix
eureka:
  client:
    registerWithEureka: true #是否将自己注册到Eureka服务中,默认为true
    fetchRegistry: true #是否从Eureka中获取注册信息,默认为true
    serviceUrl:
      defaultZone: http://localhost:5001/eureka/
server:
  port: 9091
turbine:
  appConfig: sc-client-turbine-hystrix-dashboard-node1,sc-client-turbine-hystrix-dashboard-node2 # 配置Eureka中的serviceId列表,表明监控哪些服务
  clusterNameExpression: new String("default")
  # 1. clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称
  # 2. 当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default
  # 3. 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC,则需要配置,同时turbine.aggregator.clusterConfig: ABC
  instanceUrlSuffix: /hystrix.stream
  aggregator:
    clusterConfig: default  # 指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问


6、 新建springboot启动类


package sc.client.turbine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
@EnableEurekaClient
public class TurbineApplication {
public static void main(String[] args) {
  SpringApplication.run(TurbineApplication.class, args);
}
}


7、 按照如下先后顺序启动项目


1sc-eureka-server

2sc-server-turbine-hystrix-dashboard-node1、sc-server-turbine-hystrix-dashboard-node2

3sc-client-turbine-hystrix-dashboard-node1、sc-client-turbine-hystrix-dashboard-node2

4sc-client-turbine-hystrix

 

8、 访问注册中心http://127.0.0.1:5001/确认服务都启动成功


微信图片_20220501211319.png


9、 验证Turbine集群监控


访问http://localhost:9091/turbine.stream,返回如下数据


微信图片_20220501211324.png


并且会不断刷新以获取实时的监控数据,说明单个的监控类似,返回监控项目的信息。进行图形化监控查看,输入http://localhost:9091/hystrix,返回如下界面

 

微信图片_20220501211327.png


输入 http://localhost:9091/turbine.stream,然后点击 Monitor Stream ,可以看到出现如下界面


微信图片_20220501211331.png


没有出现任何监控图表。分别访问http://127.0.0.1:5801/feign/user/getUser/1http://127.0.0.1:5802/feign/user/listUser(尽量多访问几次)

 

微信图片_20220501211335.png

 

微信图片_20220501211340.png


返回查看Turbine集群监控图表界面


微信图片_20220501211343.png


https://gitee.com/hjj520/spring-cloud-2.x

相关文章
|
2月前
|
监控 Java Sentinel
使用Sentinel进行服务调用的熔断和限流管理(SpringCloud2023实战)
Sentinel是面向分布式、多语言异构化服务架构的流量治理组件,主要以流量为切入点,从流量路由、流量控制、流量整形、熔断降级、系统自适应过载保护、热点流量防护等多个维度来帮助开发者保障微服务的稳定性。
80 3
|
2月前
|
监控
springCloud之Hystrix监控
springCloud之Hystrix监控
18 0
|
3月前
|
监控 微服务
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
40 0
|
3月前
|
监控 负载均衡 数据可视化
SpringCloud - Hystrix断路器-服务熔断与降级和HystrixDashboard
SpringCloud - Hystrix断路器-服务熔断与降级和HystrixDashboard
48 0
|
Java API Maven
SpringCloud Gateway - 集成 Sentinel 流量限流、熔断
SpringCloud Gateway - 集成 Sentinel 流量限流、熔断
2517 0
|
监控 数据可视化 Java
SpringCloud之服务监控Hystrix Dashboard
SpringCloud之服务监控Hystrix Dashboard
SpringCloud之服务监控Hystrix Dashboard
|
监控 算法 网络协议
Sentinel vs Hystrix 限流对比,到底怎么选?
Sentinel vs Hystrix 限流对比,到底怎么选?
652 0
Sentinel vs Hystrix 限流对比,到底怎么选?
|
Sentinel 微服务
【微服务~Sentinel】Sentinel降级、限流、熔断
【微服务~Sentinel】Sentinel降级、限流、熔断
1295 0
【微服务~Sentinel】Sentinel降级、限流、熔断
|
监控 Java 微服务
14、Ribbon整合断路器监控Hystrix Dashboard
今天的项目主要整合sc-eureka-client-consumer-ribbon-hystrix项目和sc-hystrix-dashboard项目
128 0
14、Ribbon整合断路器监控Hystrix Dashboard
|
监控 Java Spring
15、Feign整合断路器监控Hystrix Dashboard
本篇讲解一下Feign如何整合断路器监控Hystrix Dashboard。本篇主要整合sc-eureka-client-consumer-feign-hystrix项目和sc-hystrix-dashboard项目。
180 0
15、Feign整合断路器监控Hystrix Dashboard