当前位置:首页 >探索 >SpringCloud之Hystrix Dashboard监控搭建与配置 如下:server.port=3721 至此

SpringCloud之Hystrix Dashboard监控搭建与配置 如下:server.port=3721 至此

2024-05-14 02:46:07 [百科] 来源:避面尹邢网

SpringCloud之Hystrix Dashboard监控搭建与配置

作者:动力节点 运维 系统运维 Hystrix 仪表盘(Hystrix Dashboard),监控就像汽车的搭建仪表盘实时显示汽车的各项数据一样,Hystrix 仪表盘主要用来监控 Hystrix 的配置实时运行状态。

[[408228]]

Hystrix 仪表盘监控

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

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

SpringCloud之Hystrix Dashboard监控搭建与配置 如下:server.port=3721 至此

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

SpringCloud之Hystrix Dashboard监控搭建与配置 如下:server.port=3721 至此

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

比如创建一个名为

SpringCloud之Hystrix Dashboard监控搭建与配置 如下:server.port=3721 至此

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 仪表盘监控数据解读

 

责任编辑:姜华 来源: 今日头条 SpringCloudHystrix 监控

(责任编辑:综合)

    推荐文章
    热点阅读