当前位置:首页 > Java技术 > 正文内容

断路器监控Hystrix Dashboard的使用

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

一、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独有的。因此,在这里我用比较通俗的话说了。序列化就是把一个对象转换成有规则的二进制流。而反序列化就是把有规则的二进制数据重整成一个对象。其好处不难看见:1.可以把一个对象保存在一个文件里。例如,下载软件。当您关闭了软件,下次再打开...

Socket与ServerSocket的问题

//服务器端:import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintStream;import java.net.ServerSock...

JAVA获得一个文件夹大小

在JAVA里没有现成的方法获取一个文件夹的大小,那么我们可以用递归的方法,获取文件夹的大小。    import  java.util.*;  import  java.io.*;  class  GetFileSi...

过滤网页HTML标记

JAVA过滤HTML中的所有标记。非常好用!! package canca.regex; import java.util.regex.Matcher;import java.util.regex.Pattern; public class HtmlFilter {  priva...

字符,字节和编码

字符,字节和编码

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

Java VS .Net

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

发表评论

访客

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