zoukankan      html  css  js  c++  java
  • 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,可以得到

  • 相关阅读:
    Mac Pro 安装 Sublime Text 2.0.2,个性化设置,主题 和 插件 收藏
    Mac Pro 编译安装 Nginx 1.8.1
    Mac Pro 解压安装MySQL二进制分发版 mysql-5.6.30-osx10.11-x86_64.tar.gz(不是dmg的)
    Mac Pro 修改主机名
    Mac Pro 软件安装/个性化配置 汇总
    Mac Pro 安装 Homebrew 软件包管理工具
    Mac Pro 使用 ll、la、l等ls的别名命令
    Mac Pro 入门、遇到的问题、个性化设置 汇总
    Linux/UNIX线程(2)
    工作流引擎activiti入门
  • 原文地址:https://www.cnblogs.com/yhood/p/11573980.html
Copyright © 2011-2022 走看看