zoukankan      html  css  js  c++  java
  • 第二十五章 springboot + hystrixdashboard

    注意:

    一、hystrixdashboard

    作用:

    • 监控各个hystrixcommand的各种值。
    • 通过dashboards的实时监控来动态修改配置,直到满意为止

    仪表盘:

    二、启动hystrix

    1、下载standalone-hystrix-dashboard-1.5.3-all.jar

    • https://github.com/kennedyoliveira/standalone-hystrix-dashboard:该页面提供了一个很好的视频教学。

    2、启动hystrix-dashboard

    • java -jar -DserverPort=7979 -DbindAddress=localhost standalone-hystrix-dashboard-1.5.3-all.jar
      • 注意:其中的serverPort、bindAddress是可选参数,若不添加,默认是7979和localhost

    3、测试

    • 浏览器输入http://localhost:7979/hystrix-dashboard/,出现小熊页面就是正确了。

    三、代码

    1、pom.xml

     1         <dependency>
     2             <groupId>com.netflix.hystrix</groupId>
     3             <artifactId>hystrix-core</artifactId>
     4             <version>1.4.10</version>
     5         </dependency>
     6         <!-- http://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-metrics-event-stream -->
     7         <dependency>
     8             <groupId>com.netflix.hystrix</groupId>
     9             <artifactId>hystrix-metrics-event-stream</artifactId>
    10             <version>1.4.10</version>
    11         </dependency>

    说明:

    • hystrix-core:hystrix核心接口包
    • hystrix-metrics-event-stream:只要客户端连接还连着,hystrix-metrics-event-stream就会不断的向客户端以text/event-stream的形式推送计数结果(metrics)

    2、配置HystrixMetricsStreamServlet

     1 package com.xxx.firstboot.hystrix.dashboard;
     2 
     3 import org.springframework.boot.context.embedded.ServletRegistrationBean;
     4 import org.springframework.context.annotation.Bean;
     5 import org.springframework.context.annotation.Configuration;
     6 
     7 import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
     8 
     9 @Configuration
    10 public class HystrixConfig {
    11 
    12     @Bean
    13     public HystrixMetricsStreamServlet hystrixMetricsStreamServlet(){
    14         return new HystrixMetricsStreamServlet();
    15     }
    16     
    17     @Bean
    18     public ServletRegistrationBean registration(HystrixMetricsStreamServlet servlet){
    19         ServletRegistrationBean registrationBean = new ServletRegistrationBean();
    20         registrationBean.setServlet(servlet);
    21         registrationBean.setEnabled(true);//是否启用该registrationBean
    22         registrationBean.addUrlMappings("/hystrix.stream");
    23         return registrationBean;
    24     }
    25 }

    说明:以上方式是springboot注入servlet并进行配置的方式。

    参考:第二十四章 springboot注入servlet

    四、测试

    说明:启动服务后,输入localhost:8001/hystrix.stream,之后点击"Add Stream",最后点击"Monitor Stream"即可。

    说明

    • getHotelInfo - commandKey(其实就是servicename下的一个方法)
    • hotelService - ThreadPoolKey(不配置的情况下就是commandGroupKey,其实就是servicename)
  • 相关阅读:
    SharePoint 2013 代码实现自定义的站点模版创建Site Collection
    today's learning of english 2
    拉普拉斯变换
    today's learning of english 1
    Kubernetes集群(RKE)安装ArgoCD排坑
    Jenkins Maven镜像Surefire插件运行失败
    Jenkins加载Spring扩展库出错排查
    Elasticsearch BM25相关度评分算法超详细解释
    简单方便的堡垒机自动登录脚本
    完美的Vim学习体验:VimReference
  • 原文地址:https://www.cnblogs.com/java-zhao/p/5813439.html
Copyright © 2011-2022 走看看