微服务之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就派上用场了。

 

猜你喜欢

转载自www.cnblogs.com/zouhong/p/12812898.html