SpringCloud之Hystrix Dashboard监控搭建与配置

运维 系统运维
Hystrix 仪表盘(Hystrix Dashboard),就像汽车的仪表盘实时显示汽车的各项数据一样,Hystrix 仪表盘主要用来监控 Hystrix 的实时运行状态。

[[408228]]

Hystrix 仪表盘监控

Hystrix 仪表盘(Hystrix Dashboard),就像汽车的仪表盘实时显示汽车的各项数据一样,Hystrix 仪表盘主要用来监控 Hystrix 的实时运行状态,通过它我们可以看到 Hystrix 的各项指标信息,从而快速发现系统中存在的问题进而解决它;

要使用 Hystrix 仪表盘功能,我们首先需要有一个 Hystrix Dashboard项目,这个功能我们可以在原来的消费者应用上添加,让原来的消费者应用具备 Hystrix 仪表盘功能,但一般地,微服务架构思想是推崇服务的拆分,Hystrix Dashboard 也是一个服务,所以通常会单独创建一个新的工程专门用做 Hystrix Dashboard 服务;

搭建一个 Hystrix Dashboard 服务的步骤:

第一步:创建一个普通的 Spring Boot 工程

比如创建一个名为

springCloud-hystrix-dashboard 的 Spring Boot 工程,建立好基本的结构和配置;

第二步:添加相关依赖

在创建好的 Spring Boot 项目的 pom.xml 文件中添加相关依赖,如下:

过时了:

  1. <dependency>  
  2. <groupId>org.springframework.cloud</groupId>  
  3. <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>  
  4. <version>1.4.5.RELEASE</version>  
  5. </dependency>  

新的依赖:

  1. <!-- spring-cloud-starter-netflix-hystrix-dashboard -->  
  2. <dependency>  
  3.     <groupId>org.springframework.cloud</groupId>  
  4.     <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>  
  5. </dependency>  

第三步:入口类上添加注解

添加好依赖之后,在入口类上添加@EnableHystrixDashboard 注解开启仪表盘功能,如下:

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

第四步:属性配置

最后,我们可以根据个人习惯配置一下 application.properties 文件,如下:

  1. server.port=3721 

至此,我们的 Hystrix 监控环境就搭建好了;

Hystrix 仪表盘工程已经创建好了,现在我们需要有一个服务,让这个服务提供一个路径为/actuator/hystrix.stream 接口,然后就可以使用 Hystrix 仪表盘来对该服务进行监控了;

我们改造消费者服务,让其能提供/actuator/hystrix.stream 接口,步骤如下:

1、消费者项目需要有 hystrix 的依赖:

过时的:

  1. <!--Spring Cloud 熔断器起步依赖-->  
  2. <dependency>  
  3. <groupId>org.springframework.cloud</groupId>  
  4. <artifactId>spring-cloud-starter-hystrix</artifactId>  
  5. <version>1.4.5.RELEASE</version>  
  6. </dependency>  

新的:

  1. <!-- spring-cloud-starter-netflix-hystrix -->  
  2. <dependency>  
  3.     <groupId>org.springframework.cloud</groupId>  
  4.     <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>  
  5. </dependency>  

2、需要有一个 spring boot 的服务监控依赖:

  1. <dependency>  
  2. <groupId>org.springframework.boot</groupId>  
  3. <artifactId>spring-boot-starter-actuator</artifactId>  
  4. </dependency>  

3、配置文件需要配置 spring boot 监控端点的访问权限:

  1. management.endpoints.web.exposure.include=* 

这个是用来暴露 endpoints 的,由于 endpoints 中会包含很多敏感信息,除

了 health 和 info 两个支持直接访问外,其他的默认不能直接访问,所以我们

让它都能访问,或者指定:

  1. management.endpoints.web.exposure.include=hystrix.stream 

4、访问入口

http://localhost:8081/actuator/hystrix.stream

注意:这里有一个细节需要注意,要访问/hystrix.stream 接口,首先得访问consumer 工程中的任意一个其他接口,否则直接访问/hystrix.stream 接口时会输出出一连串的 ping: ping: …,先访问 consumer 中的任意一个其他接口,然后再访问/hystrix.stream 接口即可;

Hystrix 仪表盘监控数据解读

 

责任编辑:姜华 来源: 今日头条
相关推荐

2021-07-02 08:20:53

SpringCloudHystrix Tur监控

2022-05-13 09:05:49

Hystrix熔断器

2022-08-29 06:27:15

Nacos微服务

2023-02-03 15:16:42

SpringHystrix

2022-03-08 08:21:21

Spring日志分析系统日志数据

2009-07-07 15:45:17

JSP环境搭建

2011-03-21 11:33:09

LAMPApache

2014-01-16 14:20:38

CactiCacti监控

2011-03-21 11:43:45

LAMPPHP

2021-12-10 09:45:19

生成器配置代码

2017-04-03 21:52:30

隔离线程池分布式

2011-03-29 09:39:55

Cacti安装

2022-09-15 15:25:47

spring-微服务

2021-08-26 11:52:32

FeignWeb服务

2023-01-04 08:21:02

Loki配置日志

2019-07-04 13:10:53

Docker设计云计算

2011-03-22 15:17:19

Nagios监控

2023-12-27 08:47:41

PrometheusLinux架构

2021-03-26 06:01:45

日志MongoDB存储

2022-07-04 08:14:24

架构演变Tomcat容器架构
点赞
收藏

51CTO技术栈公众号