SpringCloud-Hystrix-Dashboard客户端服务监控

服务监控

  • 除了隔离依赖服务的调用以外,Hystrix还提供了准实时的调用监控(Hystrix Dashboard),Hystrix会持续地记录所有通过Hystrix发起的请求的执行信息,并以统计报表和图形的形式展示给用户,包括每秒执行多少请求,多少成功,多少失败等等。
  • Netflix通过hystrix-metrics-event-stream项目实现了对以上指标的监控,SpringCloud也提供了HystrixDashboard的整合,对监控内容转化成可视化界面!

监控服务测试

1. 服务监控是针对生产者(服务提供者)的,所以服务端需要做出一些配置

2. 新建一个工程作为监控平台

一、监控平台

1. 新建监控平台,端口号为9001,导入监控依赖
        <!--Hystrix-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>1.4.7.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.4.7.RELEASE</version>
        </dependency>

2. 编写配置文件
server:
  port: 9001
hystrix:
  dashboard:
    proxy-stream-allow-list: "*"

3. 为启动类添加支持监控的注解

在这里插入图片描述

@SpringBootApplication
@EnableHystrixDashboard
public class DeptConsumer_hystrix_dashboard_9001 {
    public static void main(String[] args) {
        SpringApplication.run(DeptConsumer_hystrix_dashboard_9001.class,args);
    }
}

二、服务端(生产者)

1. 所以的服务提供者都要添加被监控的依赖和Hystrix的依赖
       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>1.4.7.RELEASE</version>
        </dependency>
2. 为被监控的服务提供者的启动类添加一个Bean

在这里插入图片描述

    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        registration.addUrlMappings("/actuator/hystrix.stream");
        return registration;
    }

三、查看

  1. 启动Eureka集群-7001、7002
  2. 启动服务提供者-8001,并查看Eureka集群,服务是否注册成功
  3. 启动服务消费者-9001
  4. 尝试直接访问服务提供者,不通过消费者和注册中心,http://localhost:8001/hystrix/dept/get/2
  5. 打开服务提供者的 http://localhost:8001/actuator/hystrix.stream,查看是否在ping
  6. 打开消费者 http://localhost:9001/hystrix

在这里插入图片描述
在这里插入图片描述


tips:

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值