随笔 - 832  文章 - 2  评论 - 31  阅读 - 167万

微服务之Hystrix Dashboard监控平台的搭建

Hystrix Dashboard是什么
Hystrix提供了对于微服务调用状态的监控信息,但是需要结合spring-boot-actuator模块一起使用。Hystrix Dashboard是Hystrix的一个组件,Hystrix Dashboard提供一个断路器的监控面板,可以使我们更好的监控服务和集群的状态,仅仅使用Hystrix Dashboard只能监控到单个断路器的状态,实际开发中还需要结合Turbine使用。
Hystrix Dashboard作用:
Hystrix Dashboard主要用来实时监控Hystrix的各项指标信息。通过Hystrix Dashboard反馈的实时信息,可以帮助我们快速发现系统中存在的问题。
Hystrix Dashboard使用:
使用基于Hystrix的提供者访问数据库表数据,每访问一次都会记录是否成功以及最近10s错误百分比、超时数、熔断数、线程拒绝数、错误请求数、失败/异常数、服务请求频率等相关信息
Hystrix Dashboard监控平台:
 创建Hystrix Dashboard模块
 创建application.yml配置文件
  创建主启动类
1. 创建名为microService-hystrix-dashboard-9001的Maven项目
 2. 配置pom.xml

复制代码
        <dependencies>
            <!--依赖关系-->
            <dependency>
                <groupId>cn.zf</groupId>
                <artifactId>microService-api</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-hystrix</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-hystrix-dashboard</artifactId>
            </dependency>
        </dependencies>
复制代码

  3. 创建application.yml文件

   server:
      port: 9001

4. 创建主启动类

复制代码
 package cn.zf.springcloud;
     
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
     
    @EnableHystrixDashboard
    @SpringBootApplication
    public class HystrixDashBoard_9001 {
        public static void main(String[] args) {
            SpringApplication.run(HystrixDashBoard_9001.class,args);
        }
    }
复制代码

5. 测试

 

 


首页中并没有具体的监控信息,从页面上的内容可以知道,Hystrix Dashboard共支持三种不同的监控方式:

    默认的集群监控: http://turbine-hostname:port/turbine.stream
    指定的集群监控: http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
    单体应用的监控: http://hystrix-app:port/actuator/hystrix.stream

页面上面的几个参数局域

   最上面的输入框: 输入上面所说的三种监控方式的地址,用于访问具体的监控信息页面。
    Delay: 该参数用来控制服务器上轮询监控信息的延迟时间,默认2000毫秒。
    Title: 该参数对应头部标题Hystrix Stream之后的内容,默认会使用具体监控实例的Url。

Hystrix Dashboard监控平台的搭建:

    监控平台:使用上面的监控平台
    被监控方:服务提供者。这里接微服务之Hystrix熔断器那期代码

在microService-provider-hystrix-8002项目中的pom.xml添加新的依赖:

复制代码
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <!--添加熔断器依赖-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            </dependency>
复制代码

在application.yml文件中添加暴露点:

    #  在被监控的服务上添加暴露点
    management:
      endpoints:
        web:
          exposure:
            include: hystrix.stream
    #       include: '*'   #'*'代表开放所有端点。

启动eureka注册中心、服务提供者、服务注册者,浏览器访问http://localhost:8002/actuator/hystrix.stream出现以下页面,因为监控的实例本身还没有调用任何服务,所以监控端点也没记录任何信息:
访问一下服务:

 

 


访问后回到刚才的页面点击刷新,有数据返回,埋点生效。
从浏览器中的信息可以看出这些信息是刚刚请求微服务时所记录的监控信息,但是直接去看这些信息肯定是不友好的,所以Hystrix Dashboard就派上用场了。

 

 

 

posted on   小破孩楼主  阅读(1363)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

点击右上角即可分享
微信分享提示