详解断路器监控和聚合监控

纺织机械设备2019年10月03日

  详解断路器监控和聚合监控

   16:2 来源:

  原标题:详解断路器监控和聚合监控

  今天我们深入学习断路器监控hystrix dashboard,之前我们有过简单的使用。在微服务架构中为例保证程序的可用性,避免程序出错导致络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。hystrix dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。

  一.准备工程

  建议大家新建工程,由于这样其他的单独的服务只要进行了熔断机制的,都可以在仪表盘上面去查看,另外,如果dashboard和被监控工程整合到了一起,即使配置abled=true 也是检测不到 feign 通道的数据的,在仪表盘界面一直是 loading。所以,如果使用feign ,建议dashboard成为独立的项目。

  1.创建hystrix-dashboard,引入依赖

  !--客户端负载均衡--

  dependency

  oud/groupid

  artifactidspring-cloud-starter-ribbon/artifactid

  /dependency

  !--eureka客户端--

  dependency

  oud/groupid

  artifactidspring-cloud-starter-eureka/artifactid

  /dependency

  !--hystrix断路器--

  dependency

  oud/groupid

  artifactidspring-cloud-starter-hystrix/artifactid

  /dependency

  dependency

  ot/groupid

  artifactidspring-boot-starter-actuator/artifactid

  /dependency

  !--hystrix断路器仪表盘--

  dependency

  oud/groupid

  artifactidspring-cloud-starter-hystrix-dashboard/artifactid

  /dependency

  l配置文件

  eureka:

  client:

  serviceurl:

  defaultzone:http://localhost:8761/eureka/

  spring:

  application:

  name:hystrix-dashboard

  server:

  port:9000

  .创建一个consumercontroller控制器

  @restcontroller

  publicclassconsumercontroller{

  @autowired

  privateresttemplateresttemplate;

  @hystrixcommand(fallbackmethod=defaultstores)

  @getmapping(value=/hello)

  publicstringhello(){

  tforentity(http://eureka-client/,ass).getbody();

  }

  publicstringdefaultstores(){

  returnribbon+hystrixdashboard,提供者服务已失效;

  }

  }

  4.启动类上添加注解

  @enablehystrix

  @enablediscoveryclient

  @enablehystrixdashboard

  @springbootapplication

  publicclassribbonconsumerapplication{

  @loadbalanced

  @bean

  resttemplateresttemplate(){

  returnnewresttemplate();

  }

  publicstaticvoidmain(string[]args){

  n(ass,args);

  }

  }

  5.启动工程

  拿出我们之前的小宝贝儿们,eureka-server,eureka-client,然后我们依次启动他们,eureka-client记得最少要启动两个不同端口,最后启动hystrix-dashboard。启动好之后去http://localhost:8761看一下注册有没有成功。

  访问http://localhost:8766/ream显示

  接下来我们就该访问http://localhost:8766/ream了,但是有的小伙伴会发生以下问题:

  无限ping,这是为何呢?是由于我们还没有通过8766仪表盘访问过两个client,所以我们需要先访问一下他们

  接下来我们再去访问http://localhost:8766/ream

  我们可以看到有大量数据了,这就说明我们刚刚已经成功调用了服务,并且监控已经记录,现在我们需要去http://localhost:8766/hystrix输入信息“http://localhost:8766/hystrix”,“2000”,“hi”。

  点击下面的monitor stream然后我们就能看到还算美观的仪表盘界面:

  说了这么多,他们都分别是什么意思呢,我们来看(呕心力作之图和一张实际生产的图)。

  以上便是hystrix dashboard的一个小详解。

  二.聚合监控 hystrix turbine

  上边我们讲述了如何利用hystrix dashboard去监控断路器的hystrix command。当我们有很多个服务的时候,看单个的hystrix dashboard的数据并没有甚么多大的价值,要聚合所以服务的hystrix dashboard的数据了。这就需要用到spring cloud的另一个组件了,即hystrix turbine。要想看这个系统的hystrix dashboard数据就需要用到hystrix turbine。hystrix turbine将每个服务hystrix dashboard数据进行了整合。

  1.创建service-turbine,引入依赖

  !--

  dependency

  oud/groupid

  artifactidspring-cloud-starter-turbine/artifactid

  version1.1. .release/version

  /dependency

  dependency

  ot/groupid

  artifactidspring-boot-starter-actuator/artifactid

  /dependency

  2.在入口类serviceturbineapplication加上注解@enableturbine,开启turbine,@enableturbine注解包含了@enablediscoveryclient注解,即开启了注册服务。

  @enableturbine

  @springbootapplication

  publicclassserviceturbineapplication{

  publicstaticvoidmain(string[]args){

  n(ass,args);

  }

  }

  .配置文件l

  spring:

  :service-turbine

  server:

  port:8769

  security:

  basic:

  enabled:false

  turbine:

  aggregator:

  clusterconfig:default#指定聚合哪些集群,多个使用,分割,默认为default。

  可使用http://.../ream?cluster={clusterconfig之一}访问

  appconfig:service-hi,service-lucy###配置eureka中的serviceid列表,

  表明监控哪些服务

  clusternameexpression:newstring(default)

  #usternameexpression指定集群名称,默许表达式appname;

  此时:usterconfig需要配置想要监控的应用名称

  #2.当clusternameexpression:default时,usterconfig可以不写,

  由于默许就是default

  # .当clusternameexpression:metadata['cluster']时,假设想要监控的应用配置了

  uster:abc,则需要配置,同时

  usterconfig:abc

  eureka:

  client:

  serviceurl:

  defaultzone:http://localhost:8761/eureka/

  4.启动工程

  依次开启eureka-server、service-hi、service-lucy、service-turbine工程。

  打开浏览器输入:http://localhost:8769/ream,界面如下

  顺次要求:

  http://localhost:8762/hi?name=imooc

  http://localhost:876 /hi?name=imooc

  打开:http://localhost:876 /hystrix,输入监控流http://localhost:8769/ream

  可以看到这个页面聚合了2个service的hystrix dashbord数据。

  以上便是所有spring cloud中我所想分享给大家的内容,以这些知识作为铺垫,祝大家的技术更上一层楼~感谢大家浏览!

  :

  声明:该文观点仅代表作者本人,搜狐号系信息发布平台,搜狐仅提供信息存储空间服务。

  阅读 ()

两岁宝宝积食怎么办
儿童流鼻血的原因及治疗
小孩子不消化怎么办
相关阅读
在对的整整里,我遇见了最美的你

在对的间隔时间之中,我有一天了最美的你。倾尽人生,只为这一场动人的花...

2024-01-19
堪比好莱坞大片,看老黄如何运用三十六计,破2022高考数学分析的堡垒

2022年中考微积分全国卷I的填空压轴题,考卷人是铁了心要和试卷们自觉斗勇...

2023-11-29
芬兰将成为第三个被俄罗斯断供煤的欧洲国家

在拒绝以列伊现金后,挪威即将成为第三个被俄国断供天然气的中欧国家政府...

2023-11-06
结婚半年察觉到家暴:一段健康的恋情有多重要

小姐妹在昨天半夜打来电话,忍不住着和我却说,她被太太打了,原因是太太...

2023-10-28
恋就是让一个笨手笨脚的小女孩有人照顾 有人惦记 如果让她哭 你算什么男子汉 你算大笨蛋 艾特ta热门

恋人就是让一个笨手笨脚的莎拉有人照顾 有人惦记 如果让她不禁 你唯什么男...

2023-10-24
混合物芝麻酱,用水还是用油?弄错了,芝麻酱不香,不细腻也不顺滑

混和芝麻奶油,饮井水还是麦芽糖?才对了,芝麻奶油不香,不生动也不顺滑...

2023-10-23
友情链接