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


    上一篇,使用了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,可以得到

  • 相关阅读:
    信息系统开发平台OpenExpressApp - 支持列表分组(Group)
    WPF - 轻量级的开源XAML编辑器Kaxaml
    工作流 - 架构描述
    工作流 - 技术备忘录
    开源 - 轻型的表达式引擎 Flee
    敏捷实践(收集)
    人生就是......
    信息系统开发平台OpenExpressApp - 应用模型ApplicationModel
    软件观点 - 平台分类:系统平台、开发平台和开放平台
    软件产品线工程方法 - BAPO之架构(Architecture)
  • 原文地址:https://www.cnblogs.com/yhood/p/11573980.html
Copyright © 2020-2023  润新知