首页 > 编程语言 > 详细

SpringCloud-使用熔断器仪表盘监控熔断

时间:2019-10-21 23:07:45      阅读:95      评论:0      收藏:0      [点我收藏+]

场景

SpringCloud-使用熔断器防止服务雪崩-Ribbon和Feign方式(附代码下载):

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

在上面已经实现使用Ribbon和Feign的方式使用熔断器,但是如果服务一直在被熔断需要怎么解决。

所以这里使用熔断仪表盘监控熔断。

这里使用feign的方式使用监控。

注:

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

实现

在pom.xml中加入依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

 

然后在Application中添加注解@EnableHystrixDashboard

package com.badao.hello.spring.cloud.web.feign;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
public class WebAdminFeignApplication {
    public static void main(String[] args) {
        SpringApplication.run(WebAdminFeignApplication.class, args);
    }
}

 

 

创建hystrix.stream的Servlet配置

在包下新建config包,在config包下新建config配置类

package com.badao.hello.spring.cloud.web.feign.config;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HystrixDashboardConfiguration {
    @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;
    }
}

 

 

效果

打开浏览器,输入:

http://localhost:8765/hystrix

技术分享图片

 

 

技术分享图片

然后在url这里,输入上面在配置类中配置的url。

Delay表示监控的间隔,默认是2秒钟。

Title可以自己随意起。

技术分享图片

 

 

技术分享图片

然后点击Monitor Stream按钮。

技术分享图片

 

 

技术分享图片

此时我们多次触发熔断器,这里不启动服务提供者,使用服务消费者Feign的方式去请求服务,使其触发熔断,打开浏览器输入:

http://localhost:8765/hi?message=HelloFrign

然后再回到熔断仪表盘这里

技术分享图片

 

SpringCloud-使用熔断器仪表盘监控熔断

原文:https://www.cnblogs.com/badaoliumangqizhi/p/11716816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!