美文网首页
Hystrix仪表盘-Dashboard

Hystrix仪表盘-Dashboard

作者: zbsong | 来源:发表于2020-03-21 10:47 被阅读0次

主要用来实时监控Hystrix的各项指标信息,通过仪表盘反馈的实时信息,可以帮助我们快速的发现系统中存在的问题,从而及时的采取对应的措施。

架构图如下:

dashboard.jpeg
  • Hystix Dashboard实现
    1. 创建一个新的springboot工程,命名为:hystrix-dashboard
    2. 编辑pom.xml,主要依赖内容如下:
<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>
  1. 修改应用主类,添加@EnableHystrixDashboard 开启Hystrix Dashboard功能:
@SpringBootApplication
@EnableHystrixDashboard
public class DashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(DashboardApplication.class, args);
    }

}

4.配置端口号等信息

spring:
 application:
   name: hystrix-dashboard
server:
 port: 3000

5.到这里hystrix Dashboard配置已经基本完成,启动应用,访问http://localhost:3000/hystrix,界面如下。

dashboard-view.jpeg

从界面上标的1、2、3可以看出来,Hystrix Dashboard支持三种不同的监控方式
1、集群监控,需要整合Turbine来实现,下一章体现。
2、指定的集群监控,需要整合Turbine来实现,下一章体现。
3、单体应用监控,实现对具体的某个服务实例监控。

  • Hystix Dashboard实现以后,接下来对服务实例进行简单的修改
    1、修改ribbon-consumer(我自己创建的一个消费服务)项目
    2、pom.xml添加依赖
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

3、修改应用主类,确保使用@EnableCircuitBreaker开启了断路器功能

@EnableDiscoveryClient
@EnableCircuitBreaker
@SpringBootApplication
public class RibbonApplication {

    /**
     * LoadBalanced 开启客户端负载均衡
     * @return
     */
    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

    public static void main(String[] args) {
        SpringApplication.run(RibbonApplication.class, args);
    }
}

4、在 application.yml 文件中增加以下配置,将endpoint信息全部暴露出来,不然会出现Unable to connect to Command Metric Stream的错误:

management:
  endpoints:
    web:
      exposure:
        include: "*"
  • 到此所有配置全部结束,下面来查看效果
    1、在Hystrix Dashboard首页输入 http://localhost:8000/actuator/hystrix.stream(SpringBoot2.x版本Spring团队对原有的规则进行了修改:原来直接通过/hystrix.stream,在SpringBoot2.x版本需要加上/actuator,即/actuator/hystrix.stream),点击Monitor Stream,可以看到已经实现了对ribbon-consumer实例的监控。
dashboard4.jpeg dashboard5.jpeg

左上角两个重要信息,一个实心圆和一条曲线
实心圆:通过颜色的变化代表了实例的健康程度,它的健康度从绿色、黄色、橙色、红色递减。除了颜色变化之外,它的大小也会根据实例的请求流量变化,流量越大该实心圆就越大,如上图。
曲线:用来记录2分钟内流量的相对变化,可以通过它来观察流量的上升和下降趋势。
其它的指标含义请参考文档:https://github.com/Netflix-Skunkworks/hystrix-dashboard/wiki

相关文章

网友评论

      本文标题:Hystrix仪表盘-Dashboard

      本文链接:https://www.haomeiwen.com/subject/sjfyyhtx.html