Hystrix-Turbine-集群监控

一)集群监控

在这里插入图片描述

Turbine 是聚合服务器发送事件流数据的一个工具,hystrix 的 监控中,只能监控单个节点,实际生产中都为集群,因此可以通过 t urbine 来监控集群服务。

使用集群监控服务的时候被监控的服务需要有Dashboard的坐标

1.修改Customer添加Dashboard

<!--        使用可视化界面需要添加的坐标-->
        <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>

2.在启动类上添加注解

@EnableCircuitBreaker
@EnableHystrixDashboard、
注意:
在启动类中添加一个的方法,修改默认的获取请求流的信息,不然Turdine获取不到信息,因为Turdine默认是从http://ip:port/actuator/hystrix.stream这个的路径取信息的

@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard //开启可视化页面
@EnableCircuitBreaker //开启熔断
public class Application
{

    public static void main(String[] args)
    {
        SpringApplication.run(Application.class, args);
    }
 /**
 * 配置路径映射,获取JSON格式的请求数据
 * @return
 */
@Bean
public ServletRegistrationBean hystrixMetricsStreamServlet() {
    ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
    registration.addUrlMappings("/actuator/hystrix.stream");
    return registration;
    }

}

全局配置文件

spring.application.name=26-hystrix-turbine
server.port=9010
eureka.client.service-url.defaultZone=http://peer1:8081/eureka/,http://peer2:8082/eureka/,http://peer3:8083/eureka/



#配置 Eureka 中的 serviceId 列表,表明监控哪些服务
turbine.appConfig=21-hystrix-threadpool,23-feign-customer-fallback
#指定聚合哪些集群,多个使用","分割,默认为 default。可使用http://.../turbine.stream?cluster={clusterConfig 之一}访问
turbine.aggregator.clusterConfig=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
turbine.clusterNameExpression="default"

3.在Turdine内添加坐标

<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>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-turbine</artifactId>
</dependency>

4.修改启动类

使用注解@EnableTurbine注解开启Turbine的功能

@SpringBootApplication
@EnableTurbine //开启Turbine
public class Application
{

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

}

5.启动Customer
6.启动Turbine
请求Customer之后,使用Turbine的URL地址访问如下链接
http://localhost:9010/turbine.stream

如果能返回如下信息就是链接成功注意返回的是在Turbine内设置

在这里插入图片描述

7.启动Dashboard

在Dashboard的管理界面上输入http://localhost:9010/turbine.stream

得到集群信息,如果没有获取到信息,请按照顺序启动,

启动Customer——》请求Customer-——》请求——Customer的http://ip:port//actuator/hystrix.stream ——》启动Turbine———》请求的http://localhost:9010/turbine.stream ——》启动Dashboard——》在管理界面数据输入http://localhost:9010/turbine.stream

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值