21、断路器集群监控Turbine

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

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


(1)bootstrap.yml修改


server:
  port: 5802


(2)application.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、 按照如下先后顺序启动项目


(1)sc-eureka-server

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

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

(4)sc-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/1和http://127.0.0.1:5802/feign/user/listUser(尽量多访问几次)

 

微信图片_20220501211335.png

 

微信图片_20220501211340.png


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


微信图片_20220501211343.png


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

相关文章
|
缓存 Java 应用服务中间件
nginx的正向代理和反向代理以及tomcat
Nginx的正向代理和反向代理功能在不同的场景中具有重要作用,正向代理主要用于客户端访问控制和匿名浏览,而反向代理则用于负载均衡和高可用性服务。Tomcat作为Java Web应用服务器,与Nginx结合使用,可以显著提升Web应用的性能和稳定性。通过合理配置Nginx和Tomcat,可以构建高效、稳定和可扩展的Web服务架构。
758 11
|
域名解析 弹性计算 网络协议
nslookup 域名结果正确,但是 ping 域名失败
&gt; 最近两周碰到了不同场景下四个DNS问题,所以记录一下 这几个Case描述如下: 1. 一批ECS nslookup 域名结果正确,但是 ping 域名 返回 unknown host 1. 在公司网下,我的windows7笔记本的wifi总是报dns域名异常无法上网(通过IP地址可以上网) 1. Docker集群中两个容器中 nslookup 同一个域名,返回来的IP不一样
13118 1
|
缓存 负载均衡 应用服务中间件
【揭秘】nginx代理配置全攻略:从零到精通,一文带你玩转高效网络代理的秘密武器!
【8月更文挑战第22天】nginx是一款高性能的HTTP与反向代理服务器,支持代理服务、负载均衡及缓存等功能,有助于提升网站响应速度和安全性。首先需确保已安装nginx,可通过包管理器进行安装。安装后启动并确认nginx运行状态。接着编辑配置文件(通常位于`/etc/nginx/nginx.conf`),设置代理转发规则,例如指定目标服务器地址和请求头信息。配置完成后测试有效性并重新加载nginx以应用更改。可以通过部署简易HTTP服务器验证代理功能是否正常工作。此外,还可以通过扩展配置文件实现更复杂的代理需求,如基于路径的代理和SSL加密等。
3233 2
|
JavaScript 前端开发
Vue报错“ Uncaught TypeError: Cannot read property ‘use‘ of undefined”
Vue报错“ Uncaught TypeError: Cannot read property ‘use‘ of undefined”
1294 1
|
3天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8085 2
|
12天前
|
域名解析 人工智能 Linux
|
20天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
10405 13
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置