15-微服务熔断器-监控Hystrix-DashBoard

Hystrix-DashBoard(监控)

微服务配置了Hystrix熔断规则,Hystrix-DashBoard可以帮我们分析熔断的情况

该技术,主要用来帮助项目经理,统计/分析熔断数据

创建DashBoard的微服务
导入依赖
        <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>
修改application.yml
spring:
  application:
    name: micro-hystrix-dashboad-server
server:
  port: 7070
修改启动类

启动类上,添加@EnableHystrixDashboard

/**
 * @EnableHystrixDashboard 开启熔断器的监控功能
 */
@EnableHystrixDashboard
@SpringBootApplication
public class MicroHystrixDashboadServerApplication {

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

}
访问DashBoard

image-20210104171333207

DashBoard监控微服务
在需要修改监控的微服务中,添加依赖

例如:可以在micro-user-server中导入

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
修改启动类,添加Servlet的支持

SpringCloud使用G及其之前的版本不用写配置类,升级到H以后还有写个配置信息
在启动类身上,添加下面的代码

    /**
     * 此配置是为了服务监控而配置,与服务器容错本身无关,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;
    }
在DashBoard微服务的application.yml中,添加下属配置
hystrix:
  dashboard:
    proxy-stream-allow-list: "localhost"

添加对本机放行

访问http://localhost:9092/hystrix.stream

image-20210104173714145

通过这里的截图,我们可以发现9092所在的微服务,已经在向DashBoard发送消息

测试效果

访问:DashBoard所在的地址:http://localhost:7070/hystrix/monitor?stream=http%3A%2F%2Flocalhost%3A9092%2Fhystrix.stream&title=%E7%94%A8%E6%88%B7%E5%BE%AE%E6%9C%8D%E5%8A%A1

image-20210104174303157

1、圆点:微服务的健康状态,颜色有绿色、黄色、橙色、红色,健康状态依次降低

2、线条:流量变化 3、请求的方法 4、成功请求(绿色)5、短路请求(蓝色)

6、坏请求(青色)7、超时请求(黄色)8、被拒绝的请求(紫色)9、失败请求(红色)10、最近10秒钟内请求错误的百分比

色,健康状态依次降低

2、线条:流量变化 3、请求的方法 4、成功请求(绿色)5、短路请求(蓝色)

6、坏请求(青色)7、超时请求(黄色)8、被拒绝的请求(紫色)9、失败请求(红色)10、最近10秒钟内请求错误的百分比

11、请求频率 12、熔断器状态 13、数据延迟统计 14、线程池

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值