Spring-cloud 微服务架构搭建 04 – Hystrix 监控配合turbine的配置使用

释放双眼,带上耳机,听听看~!

文章目录

    1. Hystrix仪表盘和Turbine集群监控简介
        1. hystrix-dashboard-turbine 模块快速搭建

1. Hystrix仪表盘和Turbine集群监控简介

Hystrix仪表盘主要监控hystrix中的各项指标信息,以“桶”和“滚动时间窗的形式”,进行记录保存供外部调用。Hystrix仪表盘可以对单个服务进行监控,暴露hystrix.stream接口,Turbine整合所有服务进行监控。

2. hystrix-dashboard-turbine 模块快速搭建

注:本文项目采用idea工具进行搭建

  • 使用idea自身的spring initializr进行项目的初始化,项目名为:hystrix-dashboard-turbine。

  • 初始化完成项目之后进行pom文件导入


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1<!-- turbine 监控启动类 -->
2<dependency>
3    <groupId>org.springframework.cloud</groupId>
4    <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
5</dependency>
6<!-- hystrix-dashboard 仪表盘启动类 -->
7<dependency>
8    <groupId>org.springframework.cloud</groupId>
9    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
10</dependency>
11<!-- 注册eureka -->
12<dependency>
13    <groupId>org.springframework.cloud</groupId>
14    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
15</dependency>
16
17
  • 修改bootstrap.yml文件,添加如下配置:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
1management:
2  endpoints:
3    web:
4      exposure:
5        include: "*"  # 暴露所有服务监控端口,也可以只暴露 hystrix.stream端口
6  endpoint:
7    health:
8      show-details: ALWAYS
9#eureka.client.serviceUrl.defaultZone属性对应服务注册中心的配置内容,指定服务注册中心的位置。
10eureka:
11  client:
12    registryFetchIntervalSeconds: 5
13    serviceUrl:
14      defaultZone: http://localhost:8761/eureka/
15  instance:
16    leaseRenewalIntervalInSeconds: 10
17    hostname: localhost
18    preferIpAddress: true
19
20turbine:
21#  1.被监控的服务应用没有配置 context-path 的情况下
22  # 配置 Eureka 中的 serviceId 列表,指定要监控的服务
23#  app-config: SPRING-DEMO-SERVICE-FEIGN,SPRING-DEMO-SERVICE-RIBBON
24#  aggregator:
25#    cluster-config: default
26#  # 指定集群名称
27#  cluster-name-expression: "'default'"
28
29#  2.被监控的服务应用配置了 context-path 的情况下,此时默认是集群里的应用都配置了 context-path
30  # 配置 Eureka 中的 serviceId 列表,指定要监控的服务
31#  app-config: SPRING-DEMO-SERVICE-FEIGN
32#  aggregator:
33#    cluster-config: default
34#  # 指定集群名称
35#  cluster-name-expression: "'default'"
36#  instanceUrlSuffix: gateway/actuator/hystrix.stream
37
38#  3.被监控的服务应用一部分配置了 context-path,一部分没有配置 context-path
39  # 配置 Eureka 中的 serviceId 列表,指定要监控的服务
40  app-config: feign-service,demo-service
41  aggregator:
42    cluster-config: default
43  # 指定集群名称
44  cluster-name-expression: "'default'"
45  combine-host-port: true
46
47
  • 最后修改服务启动类:


1
2
3
4
5
6
7
8
9
10
11
1@EnableTurbine
2@EnableHystrixDashboard
3@SpringBootApplication
4public class HystrixDashboardTurbineApplication {
5
6    public static void main(String[] args) {
7        SpringApplication.run(HystrixDashboardTurbineApplication.class, args);
8    }
9}
10
11

注意:我们在第一次进入时画面显示为loading…,只有在访问了接口之后才会出现上面的画面,监控台上的控制信息详细说明可以网上查找资料……^ _ ^

turbine可以继承amqp使用消息队列进行信息监控,只需要修改spring-cloud-starter-netflix-turbinespring-cloud-starter-netflix-turbine-amqp,然后进行rabbitmq的配置后就可以使用了,但是得确保消息队列的启动无误。

本文github代码地址:
spring-cloud 基础模块搭建 – 欢迎指正

给TA打赏
共{{data.count}}人
人已打赏
安全经验

Docker安装gitlab

2021-10-11 16:36:11

安全经验

安全咨询服务

2022-1-12 14:11:49

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索