首页 > 编程语言 > 详细

spring boot 使用Hystrix-dashboard 监控Feign的单个应用

时间:2019-09-24 13:11:07      阅读:65      评论:0      收藏:0      [点我收藏+]

上一篇,使用了Feign的熔断器Hystrix,去对Consumer进行了改造,使其拥有了对服务异常的处理能力。

接下来要做对服务的访问情况进行监控

Hystrix-dashboard 熔断监控,在实际集群中同服务的节点有许多个,这里仅作单个服务节点的监控,集群中的监控会在下一篇有讲

对消费者Consumer进行改造

 pom.xml 新增3个依赖

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

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

启动类

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ApplicationStart {

    @Bean
    @LoadBalanced
    RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Bean
    public ServletRegistrationBean getServlet(){
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();    //监控实例
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);    //servlet注册接口
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/actuator/hystrix.stream");   //路径
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }

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

1.新增注解

@EnableHystrixDashboard      开启熔断监控
@EnableCircuitBreaker     开启断路器

2.注册servlet,实例化HystrixMetricsStreamServlet(较新版本需要添加,低版本略过)

启动Consumer,访问http://localhost:8051/hystrix    (8051是我这边在application配置文件中设置的端口)

技术分享图片

 

 看到这种界面,说明启动成功了,这里有3个提示

查看默认集群:http://turbine-hostname:port/turbine.stream

查看指定集群:http://turbine-hostname:port/turbine.stream?cluster=[clusterName]

查看本应用:http://hystrix-app:port/actuator/hystrix.stream

现在只查看本应用的访问情况,在输出框内输入:http://localhost:8051/actuator/hystrix.stream ,点击monitor stream

技术分享图片

 

 如果显示loading,访问一下应用地址,我这边是:http://localhost:8051/message/remote/hello/   之后再回去看就有了

如果想单独将监控数据拿出来,自己做预警,如邮件通知,短信通知,可以直接调用接口http://localhost:8051/actuator/hystrix.stream,可以得到

技术分享图片

 

spring boot 使用Hystrix-dashboard 监控Feign的单个应用

原文:https://www.cnblogs.com/yhood/p/11573980.html

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