Spring Cloud(五):Hystrix 监控面板【Finchley 版】

 发表于 2018-04-16 |  更新于 2018-05-10 | 

上一篇 Hystrix 的介绍中,我们提到断路器是根据一段时间窗内的请求情况来判断并操作断路器的打开和关闭状态的。而这些请求情况的指标信息都是 HystrixCommand 和 HystrixObservableCommand 实例在执行过程中记录的重要度量信息,它们除了 Hystrix 断路器实现中使用之外,对于系统运维也有非常大的帮助。这些指标信息会以 “滚动时间窗” 与 “桶” 结合的方式进行汇总,并在内存中驻留一段时间,以供内部或外部进行查询使用,Hystrix Dashboard 就是这些指标内容的消费者之一。

下面我们基于之前的示例来结合 Hystrix Dashboard 实现 Hystrix 指标数据的可视化面板,这里我们将用到下之前实现的几个应用,包括:

  • eureka-server:服务注册中心
  • eureka-producer:服务提供者
  • eureka-consumer-feign-hystrix:使用 Feign 和 Hystrix 实现的服务消费者

创建 Hystrix Dashboard

创建一个标准的 Spring Boot 工程,命名为:hystrix-dashboard

POM 配置

在 pom.xml 引入相关的依赖

复制

1
2
3
4
5
6
7
8
<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>

启动类

在 Spring Boot 的启动类上面引入注解@EnableHystrixDashboard,启用 Hystrix Dashboard 功能。

复制

1
2
3
4
5
6
7
8
@EnableHystrixDashboard
@SpringBootApplication
public class HystrixDashboardApplication { public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}

配置文件

修改配置文件 application.yml

复制

1
2
3
4
5
spring:
application:
name: hystrix-dashboard
server:
port: 11000

启动应用,然后再浏览器中输入 http://localhost:11000/hystrix 可以看到如下界面

通过 Hystrix Dashboard 主页面的文字介绍,我们可以知道,Hystrix Dashboard 共支持三种不同的监控方式:

前两者都对集群的监控,需要整合 Turbine 才能实现。这一部分我们先实现对单体应用的监控,这里的单体应用就用我们之前使用 Feign 和 Hystrix 实现的服务消费者——eureka-consumer-feign-hystrix。

页面上的另外两个参数:

  • Delay:控制服务器上轮询监控信息的延迟时间,默认为 2000 毫秒,可以通过配置该属性来降低客户端的网络和 CPU 消耗。
  • Title:该参数可以展示合适的标题。

为服务实例添加 endpoint

既然 Hystrix Dashboard 监控单实例节点需要通过访问实例的/actuator/hystrix.stream接口来实现,自然我们需要为服务实例添加这个 endpoint。

POM 配置

在服务实例pom.xml中的dependencies节点中新增spring-boot-starter-actuator监控模块以开启监控相关的端点,并确保已经引入断路器的依赖spring-cloud-starter-netflix-hystrix

复制

1
2
3
4
5
6
7
8
<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>

启动类

为启动类添加@EnableCircuitBreaker@EnableHystrix注解,开启断路器功能。

复制

1
2
3
4
5
6
7
8
9
@EnableHystrix
@EnableFeignClients
@SpringBootApplication
public class EurekaConsumerHystrixApplication { public static void main(String[] args) {
SpringApplication.run(EurekaConsumerHystrixApplication.class, args);
}
}

配置文件

在配置文件 application.yml 中添加

复制

1
2
3
4
5
management:
endpoints:
web:
exposure:
include: hystrix.stream

management.endpoints.web.exposure.include这个是用来暴露 endpoints 的。由于 endpoints 中会包含很多敏感信息,除了 health 和 info 两个支持 web 访问外,其他的默认不支持 web 访问。详情请看 50. Endpoints

测试

在 Hystrix-Dashboard 的主界面上输入 eureka-consumer-feign-hystrix 对应的地址 http://localhost:9004/actuator/hystrix.stream 然后点击 Monitor Stream 按钮,进入页面。

如果没有请求会一直显示 “Loading…”,这时访问 http://localhost:9004/actuator/hystrix.stream 也是不断的显示 “ping”。

这时候访问一下 http://localhost:9004/hello/windmt,可以看到 Hystrix Dashboard 中出现了类似下面的效果

如果在这个页面看到报错:Unable to connect to Command Metric Stream.,可以参考这个 Issue 解决。

界面解读


以上图来说明其中各元素的具体含义:

  • 实心圆:它有颜色和大小之分,分别代表实例的监控程度和流量大小。如上图所示,它的健康度从绿色、黄色、橙色、红色递减。通过该实心圆的展示,我们就可以在大量的实例中快速的发现故障实例和高压力实例。
  • 曲线:用来记录 2 分钟内流量的相对变化,我们可以通过它来观察到流量的上升和下降趋势。
  • 其他一些数量指标如下图所示

到此单个应用的熔断监控已经完成。

相关阅读

Spring Cloud(一):服务治理技术概览
Spring Cloud(二):服务注册与发现 Eureka
Spring Cloud(三):服务提供与调用 Eureka
Spring Cloud(四):服务容错保护 Hystrix
Spring Cloud(五):Hystrix 监控面板
Spring Cloud(六):Hystrix 监控数据聚合 Turbine
Spring Cloud(七):配置中心(Git 版与动态刷新)
Spring Cloud(八):配置中心(服务化与高可用)
Spring Cloud(九):配置中心(消息总线)
Spring Cloud(十):服务网关 Zuul(路由)
Spring Cloud(十一):服务网关 Zuul(过滤器)
Spring Cloud(十二):分布式链路跟踪(Sleuth 与 Zipkin)

示例代码:GitHub

参考

springcloud(五):熔断监控 Hystrix Dashboard 和 Turbine
Spring Cloud 构建微服务架构:Hystrix 监控面板【Dalston 版】
Unable to connect to Command Metric Stream

Spring Cloud(五):Hystrix 监控面板【Finchley 版】的更多相关文章

  1. spring cloud(五) hystrix

    开启feign 熔断 hystrix    整合hystrix-dashboard监控面板 1. 服务调用者boot工程 pom引入依赖 <!-- hystrix-dashboard 监控依赖 ...

  2. 从零开始学spring cloud(十一) -------- hystrix监控

    一.官方文档阅读 服务启动后,可以通过/health和hystrix.stream查看效果,实际上,访问上述两个地址,会出现404,这是因为spring boot版本的问题, 我在这里使用的sprin ...

  3. spring cloud(五)熔断监控Hystrix Dashboard和Turbine

    Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数 ...

  4. Spring Cloud中Hystrix、Ribbon及Feign的熔断关系是什么?

    导读 今天和大家聊一聊在Spring Cloud微服务框架实践中,比较核心但是又很容易把人搞得稀里糊涂的一个问题,那就是在Spring Cloud中Hystrix.Ribbon以及Feign它们三者之 ...

  5. Spring Cloud中Hystrix 线程隔离导致ThreadLocal数据丢失问题分析

    最近spring boot项目中由于使用了spring cloud 的hystrix 导致了threadLocal中数据丢失,其实具体也没有使用hystrix,但是显示的把他打开了,导致了此问题. 导 ...

  6. spring cloud Hystrix监控面板Hystrix Dashboard和Turbine

    我们提到断路器是根据一段时间窗内的请求情况来判断并操作断路器的打开和关闭状态的.而这些请求情况的指标信息都是HystrixCommand和HystrixObservableCommand实例在执行过程 ...

  7. Spring Cloud架构教程 (一)Hystrix监控面板

    下面我们基于之前的示例来结合Hystrix Dashboard实现Hystrix指标数据的可视化面板,这里我们将用到下之前实现的几个应用,包括: eureka-server:服务注册中心 eureka ...

  8. Spring Cloud(三) --- hystrix

    Hystrix 说到Hystrix就得先说一下产生的背景等等,那就是雪崩效应. 在微服务中肯定存在多个服务层之间的调用,基础服务的故障可能会导致级联故障,进而造成整个系统不可用的情况,这种现象被称为服 ...

  9. 白话SpringCloud | 第六章:Hystrix监控面板及数据聚合(Turbine)

    前言 前面一章,我们讲解了如何整合Hystrix.而在实际情况下,使用了Hystrix的同时,还会对其进行实时的数据监控,反馈各类指标数据.今天我们就将讲解下Hystrix Dashboard和Tur ...

随机推荐

  1. Mysql数据库的简单语法

    Mysql数据库是目前使用最为广泛的数据对,对于小型企业的支持度,比oracle数据库友好很多. mysql数据库的基本语法 1:创建并且使用数据库 找出服务器上当前存在什么数据库: SHOW DAT ...

  2. NSArray中地内存管理 理解

    问题: 通过alloc和init的方法创建了NSArray和NSDictionary,然后通过addobject和setobject:forkey:将object添加进去.通过addobject会自动 ...

  3. 使用OrgChart插件生成家谱组织结构图

    1.orgchart插件: github地址:https://github.com/dabeng/OrgChart 2.前端代码: //1.加载树形数据:ajax请求获取json格式的数据(flag参 ...

  4. Nlog日志出坑合集

    .net core框架下nlog不记录: 1.安装NLog.Web.AspNetCore 2.在Startup.cs文件的方法public void Configure(IApplicationBui ...

  5. iOS视频播放(AVFoundation)

    iOS视频播放(AVFoundation) 关于iOS平台的音视频处理,苹果官方提供了OC和swift接口的AVFoundation框架,可以进行各种音频播放和剪辑,底层实现使用了GPU加速,编解码效 ...

  6. 浅析Vue原理(部分源码解析)

    响应式 Object.defineProperty Object.defineProperty(obj, prop, descriptor) // 对象.属性.描述符 Object.definePro ...

  7. xtrabackup全量备份+binlog基于时间点恢复

    1.通过xtrabackup的备份恢复数据库. 2.找到start-position和binlog名称 cat xtrabackup_info 3.导出mysqlbinlog为sql文件,并确定恢复的 ...

  8. mac Axure RP 8 授权码 以及汉化

    Koshy wTADPqxn3KChzJxLmUr5jTTitCgsfRkftQQ1yIG9HmK83MYSm7GPxLREGn+Ii6xY 汉化包 汉化包链接 密码: upri 汉化步骤 以Win7 ...

  9. (Nagios)-check_openmanage[Dell]

      Nagios->check_openmanage[Dell R7*] 2014年11月13日 下午 07:44 需求介绍: 透过Nagios监控Dell R7系列服务器硬件状态 环境信息: ...

  10. Oracle条件判断列数量非where

    sum(case when typename='测试' then 1 else 0 end)