1.简单介绍

服务监控 hystrixDashboard
除了隔离依赖服务的调用以外,Hystrix还提供了准实时的调用监控(Hystrix Dashboard),Hystrix会
持续地记录所有通过Hystrix发起的请求的执行信息,并以统计报表和图形的形式展示给用户,包括每秒
执行多少请求,多少成功,多少失败等等。
Netflix通过hystrix-metrics-event-stream项目实现了对以上指标的监控,SpringCloud也提供了Hystrix
Dashboard的整合,对监控内容转化成可视化界面!

2.相关配置

新建工程springcloud-consumer-hystrix-dashboard-9001
Pom.xml
复制之前80项目的pom文件,新增以下依赖!


  1. <dependency>

  2. <groupId>org.springframework.cloud</groupId>

  3. <artifactId>spring-cloud-starter-hystrix</artifactId>

  4. <version>1.4.7.RELEASE</version>

  5. </dependency>

  6. <dependency>

  7. <groupId>org.springframework.cloud</groupId>

  8. <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>

  9. <version>1.4.7.RELEASE</version>

  10. </dependency>

将端口号改为9001

修改主启动类:


  1. package com.csh.springcloud;

  2. import org.springframework.boot.SpringApplication;

  3. import org.springframework.boot.autoconfigure.SpringBootApplication;

  4. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

  5. import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

  6. import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

  7. import org.springframework.cloud.openfeign.EnableFeignClients;

  8. import org.springframework.context.annotation.ComponentScan;

  9. @SpringBootApplication

  10. @EnableHystrixDashboard//新注解,开启功能

  11. public class Springcloudconsumer80feigndashboard {

  12. public static void main(String[] args) {

  13. SpringApplication.run(Springcloudconsumer80feigndashboard.class,args);

  14. }

  15. }

然后在provider中pom.xml文件中添加:


  1. <dependency>

  2. <groupId>org.springframework.boot</groupId>

  3. <artifactId>spring-boot-starter-actuator</artifactId>

  4. </dependency>

在 springcloud-provider-dept-hystrix-8001 启动类中增加一个bean:


  1. @Bean

  2. public ServletRegistrationBean hy()

  3. {

  4. ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());

  5. servletRegistrationBean.addUrlMappings(“/actuator/hystrix.stream”);

  6. return servletRegistrationBean;

  7. }

3.结果

Delay : 该参数用来控制服务器上轮询监控信息的延迟时间,默认为2000毫秒,可以通过配置
该属性来降低客户端的网络和CPU消耗
Title : 该参数对应了头部标题HystrixStream之后的内容,默认会使用具体监控实例URL,可
以通过配置该信息来展示更合适的标题。

 

一圈
实心圆:公有两种含义,他通过颜色的变化代表了实例的健康程度
它的健康程度从绿色<黄色<橙色<红色 递减
该实心圆除了颜色的变化之外,它的大小也会根据实例的请求流量发生变化,流量越
大,该实心圆就越大,所以通过该实心圆的展示,就可以在大量的实例中快速发现故障
实例和高压力实例。

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐