服务监控

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

 监控服务测试

1. 服务监控是针对客户端(消费者)的,所以客户端需要做出一些配置

2. 普通消费者只需要添加hystrix和dashboard的依赖+@enablehystrixdashboard就可以把消费者变成一个监控中心,同时也失去了消费者的功能,不能再访问注册中心

 一、客户端(消费者)

1. 新建消费者服务9001(复制),新增监控依赖

   <!--hystrix-->
    <dependency>
      <groupid>org.springframework.cloud</groupid>
      <artifactid>spring-cloud-starter-hystrix</artifactid>
      <version>1.4.7.release</version>
    </dependency>

    <dependency>
      <groupid>org.springframework.cloud</groupid>
      <artifactid>spring-cloud-starter-hystrix-dashboard</artifactid>
      <version>1.4.7.release</version>
    </dependency>

2. 修改配置文件

server:
 port: 9001
hystrix:
 dashboard:
  proxy-stream-allow-list: "*"

3. 为启动类添加支持监控的注解

//eureka和ribbon整合以后,客户端可以根据服务名称直接调用,不用关心ip地址和端口号
@springbootapplication
@enablehystrixdashboard
//@ribbonclient(name = "springcloud-provider-dept",configuration = myloaderbalanceconfig.class)  //在微服务启动的时候加载自定义的ribbon
public class deptconsumer_hystrix_dashboard_9001 {
  public static void main(string[] args) {
    springapplication.run(deptconsumer_hystrix_dashboard_9001.class,args);
  }
}

二、服务端(生产者)

1. 所以的服务提供者都要添加被监控的依赖和hystrix的依赖

 <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-starter-actuator</artifactid>
    </dependency>
    
    <dependency>
      <groupid>org.springframework.cloud</groupid>
      <artifactid>spring-cloud-starter-hystrix</artifactid>
      <version>1.4.7.release</version>
    </dependency>

2. 为被监控的服务提供者的启动类添加一个bean

  @bean
  public servletregistrationbean hystrixmetricsstreamservlet() {
    servletregistrationbean registration = new servletregistrationbean(new hystrixmetricsstreamservlet());
    registration.addurlmappings("/actuator/hystrix.stream");
    return registration;
  }

三、查看

  1.  启动eureka集群-7001、7002
  2. 启动服务提供者-8001,并查看eureka集群,服务是否注册成功
  3. 启动服务消费者-9001
  4. 尝试直接访问服务提供者,不通过消费者和注册中心,
  5. 打开服务提供者的 ,查看是否在ping
  6. 打开消费者

疑问:9001作为一个消费者模块,为什么不能访问生产者,难道这个模块只是用来监控的平台?

tips:

到此这篇关于springcloud-hystrix-dashboard客户端服务监控的文章就介绍到这了,更多相关springcloud-hystrix-dashboard服务监控内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!