当前位置:首页 > Java技术

断路器监控Hystrix Dashboard的使用

canca5年前 (2021-02-26)Java技术609

一、Hystrix Dashboard

作用:
  • 实时监控各个Hystrix commandKey的各种指标值

  • 通过 Dashboards 的实时监控来动态修改各种配置

仪表盘:

Alt

二、启动Hystrix Dashboard

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

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

        <!-- https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-core -->
        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-core</artifactId>
            <version>${hystrix-version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-javanica -->
        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-javanica</artifactId>
            <version>${hystrix-version}</version>
        </dependency>
        <!-- http://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-metrics-event-stream -->
        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-metrics-event-stream</artifactId>
            <version>${hystrix-version}</version>
        </dependency>

说明:

  • hystrix-core:hystrix核心接口包。

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

2、HystrixConfig.java

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
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 HystrixConfig {

    @Bean
    @HystrixProperty(name = "circuitBreaker.enabled", value = "true")
    public HystrixCommandAspect hystrixCommandAspect() {
        return new HystrixCommandAspect();
    }

    /**
     * Send stream message to Hystrix-dashboard
     */
    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet() {
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        registrationBean.addUrlMappings("/hystrix.stream");
        return registrationBean;
    }
}

3、Controller代码

4、测试
浏览器访问 http://localhost:7979/hystrix-dashboard/ ,在控制台输入spring-boot 应用的监控的地址。
Alt
说明: 启动服务后,输入 http://localhost:8080/hystrix.stream ,之后点击“Add Stream”,最后点击“Monitor Stream”即可。

Alt

说明:

  • hystrix2/test1 - commandKey(默认是方法名,可以通过@HystrixCommand的属性commandKey指定。存在2个方法名一样时必须指定

  • HystrixController2 - ThreadPoolKey(默认取类名,可以通过@HystrixCommand的属性threadPoolKey指定)


扫描二维码推送至手机访问。

版权声明:本文由Ant.Master's Blog发布,如需转载请注明出处。

本文链接:https://iant.work/post/760.html

分享给朋友:

“断路器监控Hystrix Dashboard的使用” 的相关文章

Java语言的反射机制

    由于项目的需要,在项目中要实现即插即用的方式,也就是说可以动态地加载包,不用设置CLASSPATH路径。当项目发布时,不可能要用户来设置环境变量吧!因此,就要用到JAVA的反射机制了。昨天,我是在研究JAVA的...…

JSP与Servlet的对应关系

以前在QQzone写下的文章现在贴到这里来了... 最近比较忙啊!现在抽身写一篇文章。是关于JSP与Servlet的对应关系的。希望对大家有所帮助。其实我也是刚刚学的......-------Servlet--------------JSP----------1.ServletContext&nbs…

IM技术(1)

    做项目了,NetCL今天开工了,在这些日子里,我会将自己研究的内容写下来。做个记录,以下是我在网上搜到的。关于管理用户状态的解决方案,当然,我都有一个方案。不过对客户端的任务有点重吧,我方法是客...…

JAVA内部类终极实例

最近心情不好,不想说太多东西了!电脑坏了,我现在又病了. class ClassFactory{ private final static String userName = "Hello,My name is CAnca."; public static Thread in =…

字符,字节和编码

字符,字节和编码

转自:http://www.regexlab.com/zh/encoding.htm------------------------------------------------------------- 级别:中级 摘要:本文介绍了字符与编码的发展过程,相关概念的正确理解。举例说明了一些实际应…

Java VS .Net

Java //C.java  class A  {      public A()      {       …

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。