使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控

发布时间:2021-03-09 16:01:06 作者:Leah
来源:亿速云 阅读:148

本篇文章为大家展示了使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

服务监控

 监控服务测试

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. 为启动类添加支持监控的注解

使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控

//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

使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控

  @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. 尝试直接访问服务提供者,不通过消费者和注册中心,http://localhost:8001/hystrix/dept/get/2

  5. 打开服务提供者的 http://localhost:8001/actuator/hystrix.stream,查看是否在ping

  6. 打开消费者 http://localhost:9001/hystrix

使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控
使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控

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


tips:

使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控

使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控
使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控

上述内容就是使用SpringCloud-Hystrix-Dashboard怎么客户端服务进行监控,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 使用prometheus和blackbox_exporte进行业务服务监控
  2. 2.2 nagios 监控客户端

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springcloud hystrix dashboard

上一篇:怎么在c#中利用socket实现一个心跳超时检测的功能

下一篇:yii2获取sql语句的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》