Hystrix Dashboard 配置及图形化监控

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

配置

相关依赖

 <dependencies>

        <!-- hystrix dashboard 图形化监控依赖 -->
        <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.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

主启动类 再加上 @EnableHystrixDashboard 开启dashboard监控

相关依赖

每个被监控的服务都要有豪猪 hystrix 并且主启动类开启 @EnableCircuitBreaker 熔断

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

另外!

由于springcloud 升级的坑 --- SerlvetRegistrationBean 因为 springboot 的默认路径不是 "/hystrix.stream" 需要在被监控的项目的主启动类中配置一下下面的servlet

    @Bean
    public ServletRegistrationBean getServlet()
    {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }

说明图

请求频率为 服务请求频率

百分位延迟统计为 最后一分钟的百分位延迟统计

猜你喜欢

转载自www.cnblogs.com/nineberg/p/12655861.html