SpringCloud - Spring Cloud Netflix 之 Hystrix Dashboard仪表盘监控(九)

阅读本文前可先参考

SpringCloud - Spring Cloud根/父项目,开发准备(二)_MinggeQingchun的博客-CSDN博客

https://blog.csdn.net/MinggeQingchun/article/details/125308948

https://blog.csdn.net/MinggeQingchun/article/details/125312594

一、Hystrix Dashboard

Hystrix 仪表盘(Hystrix Dashboard是Spring Cloud的仪表盘组件,可以查看Hystrix实例的执行情况,支持查看单个实例和查看集群实例,但是需要结合spring-boot-actuator一起使用。

Hystrix Dashboard主要用来实时监控Hystrix的各项指标信息。Hystrix Dashboard可以有效地反映出每个Hystrix实例的运行情况,帮助我们快速发现系统中的问题,从而采取对应措施

1、新建一个springboot Module(springcloud-6-service-eureka-hystrix-dashboard),设置父项目

2、添加 spring-cloud-starter-hystrix-dashboard等 依赖

<!-- spring-cloud-starter-netflix-hystrix-dashboard -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
<!--继承统一的父项目-->
    <parent>
        <groupId>com.company</groupId>
        <artifactId>springcloud-demo</artifactId>
        <version>1.0.0</version>
    </parent>

    <groupId>com.company</groupId>
    <artifactId>springcloud-6-service-eureka-hystrix-dashboard</artifactId>
    <version>1.0.0</version>

    <name>springcloud-6-service-eureka-hystrix-dashboard</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!--spring web 起步依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- springboot 开发自动热部署 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- spring-cloud-starter-netflix-hystrix-dashboard -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

3、application.prperties配置文件中配置访问端口3721

4、在 Spring Boot 的启动类中,添加@EnableHystrixDashboard 注解,开启仪表盘功能

@EnableHystrixDashboard  //启用Dashboard服务可用
@SpringBootApplication
public class EurekaHystrix6DashboardApplication {

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

}

5、启动springboot启动类,访问应用,再去查看 Hystrix Dashboard 控制台服务 http://localhost:3721/hystrix

Hystrix 仪表盘工程创建好之后,需要一个服务,让这个服务提供 一个路径为/actuator/hystrix.stream 接口,然后就可以使用 Hystrix 仪表盘来对该服务进行监控了

1、在消费者项目(springcloud-6-service-eureka-hystrix-consumer)添加 hystrix 的依赖 和springboot的一个监控actuator 依赖

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

        <!--springboot的一个监控actuator
            让这个服务提供一个路径为/actuator/hystrix.stream 接口,然后就可以使用 Hystrix 仪表盘来对该服务进行监控
        -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

2、配置文件需要配置 spring boot 监控端点的访问权限

#配置 spring boot 监控端点的访问权限
#暴露 endpoints,由于endpoints 中会包含很多敏感信息,除了 health 和 info 两个支持直接访问外,其他的默认不能直接访问
#或者指定
#management.endpoints.web.exposure.include=hystrix.stream
management.endpoints.web.exposure.include=*

3、访问入口 http://localhost:8081/actuator/hystrix.stream

要访问/hystrix.stream 接口,首先得访问 consumer 工程中的任意一个其他接口,否则直接访问/hystrix.stream 接口时会输出出一连串的 ping: ping: …,先访问 consumer 中的任意一个其他接口,然后再访问/hystrix.stream 接口即可

首先访问 consumer 工程中的任意一个其他接口

这时在访问 http://localhost:8081/actuator/hystrix.stream 就有数据

4、在DashBoard中输入 http://localhost:8081/actuator/hystrix.stream ,点击 Monitor Stream 

 ​​​​​​

 仪表盘开始监控

Hystrix 仪表盘监控数据解读

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值