简介

Hystrix集群监控使用的是turbine,而turbine是基于Dashboard的

组建Hystrix集群

新建一个Module,该Module为Maven项目,命名为:microservice-student-provider-hystrix-1005,把microservice-student-provider-hystrix-1004的所有文件都复制一份过来,修改几个地方:

修改application.yml

server.port修改为:1005,eureka.instance.instance-id: microservice-student-hystrix修改为:1005

修改启动类

如果启动类是复制过来的,重命名为:StudentProviderHystrixApplication_1005

新建集群监控项目

新建一个Module,命名为:microservice-student-consumer-hystrix-turbine-91

添加依赖

1
2
3
4
5
6
7
8
9
10
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
</dependencies>

继承父项目的依赖版本

1
2
3
4
5
6
<!--继承microservice依赖版本-->
<parent>
<groupId>org.example</groupId>
<artifactId>microservice</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

application.yml配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
server:
port: 91
context-path: /

eureka:
client:
service-url:
defaultZone: http://eureka2001.ledao.com:2001/eureka/,http://eureka2002.ledao.com:2002/eureka/,http://eureka2003.ledao.com:2003/eureka/

turbine:
app-config: microservice-student # 指定要监控的应用名称
clusterNameExpression: "'default'" #表示集群的名字为default

spring:
application:
name: turbine

新建启动类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.ledao;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

/**
* Hystrix集群监控启动类
*
* @author LeDao
* @company
* @create 2021-08-16 1:03
*/
@EnableTurbine
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class StudentConsumerTurbineApplication_91 {

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

测试

启动以下项目

microservice-eureka-server-2001

microservice-eureka-server-2002

microservice-eureka-server-2003

microservice-student-provider-hystrix-1004

microservice-student-provider-hystrix-1005

microservice-student-consumer-80

microservice-student-consumer-hystrix-dashboard-90

microservice-student-consumer-hystrix-turbine-91

调用服务集群

浏览器地址栏输入:http://localhost/student/getInfo

监控数据

浏览器地址栏输入:http://localhost:91/turbine.stream

如果使用图形界面监控,则先输入:http://localhost:90/hystrix 打开图形监控界面,在第一个输入框输入:http://localhost:91/turbine.stream ,再点击按钮即可