• SpringCloud中集成Hystrix后通过Dashboard实现图形化监控实现


    场景

    SpringCloud中集成Hystrix实现服务降级(从实例入手):

    https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/124948025

    SpringCloud中集成Hystrix实现熔断(从实例入手):

    https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/124968156

    在上面集成Hystrix实现服务降级与熔断的基础上,怎样搭建可视化监控平台。

    注:

    博客:
    https://blog.csdn.net/badao_liumang_qizhi
    关注公众号
    霸道的程序猿
    获取编程相关电子书、教程推送与免费下载。

    实现

    1、与上面流程一样新建子模块cloud-consumer-hystrix-dashboard9002

    pom文件中添加依赖

        <dependencies>
            <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>
        </dependencies>

    2、新建并修改application.yml

    server:
      port: 9002

    3、新建启动类并添加@EnableHystrixDashboard注解

    package com.badao.springclouddemo;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
    
    
    @SpringBootApplication
    @EnableHystrixDashboard
    public class HystrixDashboardMain9002
    {
        public static void main(String[] args) {
                SpringApplication.run(HystrixDashboardMain9002.class, args);
        }
    }

    4、启动服务,访问

    http://127.0.0.1:9002/hystrix

    5、比如这里要监控服务提供者8001

    则在输入框中输入

    http://127.0.0.1:8001/hystrix.stream

    然后Delay输入2000,Title输入T3,点击Monitor Stream

    此时DashBoard提示 Unable to connect to Command Metric Stream

    这是因为springcloud升级之后的bug,ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",

    所以在8001主启动类中添加配置

        @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;
        }

    完整启动类

    package com.badao.springclouddemo;
    
    import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.web.servlet.ServletRegistrationBean;
    import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    import org.springframework.context.annotation.Bean;
    
    
    @SpringBootApplication
    @EnableEurekaClient
    @EnableCircuitBreaker
    public class PaymentHystrixMain8001
    {
        public static void main(String[] args) {
                SpringApplication.run(PaymentHystrixMain8001.class, args);
        }
    
        /**
         *此配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑
         *ServletRegistrationBean因为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;
        }
    }

    然后此时重新对8001进行监控,并调用8001的接口

    还可以触发熔断,可以在面板中看到Circuit即为显示熔断器是否开启

    6、图形化怎么看

    首先7种颜色的个数分别对应7种状态

    圆圈代表的意思

    它通过颜色的变化代表了实例的健康程度,它的健康度从绿色<黄色<橙色<红色递减。

    它的大小也会根据实例的请求流量发生变化,流量越大该圆越大。

    所以通过该实心圆的展示,就可以在大量的实例中快速发现故障实例和高压力实例。

    整图说明

  • 相关阅读:
    常见寻找OEP脱壳的方法
    Windows内核原理系列01
    HDU 1025 Constructing Roads In JGShining's Kingdom
    HDU 1024 Max Sum Plus Plus
    HDU 1003 Max Sum
    HDU 1019 Least Common Multiple
    HDU 1018 Big Number
    HDU 1014 Uniform Generator
    HDU 1012 u Calculate e
    HDU 1005 Number Sequence
  • 原文地址:https://www.cnblogs.com/badaoliumangqizhi/p/16312769.html
Copyright © 2020-2023  润新知