首页 >> 套筒

详解断路器监控和聚合监控U盘代理


2023年04月09日

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

2018-09-18 16:23来源:

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

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

一.准备工程

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

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

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

dependency

groupidorg.springframework.cloud/groupid

artifactidspring-cloud-starter-ribbon/artifactid

/dependency

!--eureka客户端--

dependency

groupidorg.springframework.cloud/groupid

artifactidspring-cloud-starter-eureka/artifactid

/dependency

!--hystrix断路器--

dependency

groupidorg.springframework.cloud/groupid

artifactidspring-cloud-starter-hystrix/artifactid

/dependency

dependency

groupidorg.springframework.boot/groupid

artifactidspring-boot-starter-actuator/artifactid

/dependency

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

dependency

groupidorg.springframework.cloud/groupid

artifactidspring-cloud-starter-hystrix-dashboard/artifactid

/dependency

2.yml配置文件

eureka:

client:

serviceurl:

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

spring:

application:

name:hystrix-dashboard

server:

port:9000

3.创建一个consumercontroller控制器

@restcontroller

publicclassconsumercontroller{

@autowired

privateresttemplateresttemplate;

@hystrixcommand(fallbackmethod=defaultstores)

@getmapping(value=/hello)

publicstringhello(){

returnresttemplate.getforentity(http://eureka-client/,string.class).getbody();

}

publicstringdefaultstores(){

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

}

}

4.启动类上添加注解

@enablehystrix

@enablediscoveryclient

@enablehystrixdashboard

@springbootapplication

publicclassribbonconsumerapplication{

@loadbalanced

@bean

resttemplateresttemplate(){

returnnewresttemplate();

}

publicstaticvoidmain(string[]args){

springapplication.run(ribbonconsumerapplication.class,args);

}

}

5.启动工程

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

访问http://localhost:8766/hystrix.stream显示

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

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

接下来我们再去访问http://localhost:8766/hystrix.stream

我们可以看到有大量数据了,这就说明我们刚刚已经成功调用了服务,并且监控已经记录,现在我们需要去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,引入依赖

!--https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-turbine--

dependency

groupidorg.springframework.cloud/groupid

artifactidspring-cloud-starter-turbine/artifactid

version1.1.3.release/version

/dependency

dependency

groupidorg.springframework.boot/groupid

artifactidspring-boot-starter-actuator/artifactid

/dependency

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

@enableturbine

@springbootapplication

publicclassserviceturbineapplication{

publicstaticvoidmain(string[]args){

springapplication.run(serviceturbineapplication.class,args);

}

}

3.配置文件application.yml

spring:

application.name:service-turbine

server:

port:8769

security:

basic:

enabled:false

turbine:

aggregator:

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

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

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

表明监控哪些服务

clusternameexpression:newstring(default)

#1.clusternameexpression指定集群名称,默认表达式appname;

此时:turbine.aggregator.clusterconfig需要配置想要监控的应用名称

#2.当clusternameexpression:default时,turbine.aggregator.clusterconfig可以不写,

因为默认就是default

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

eureka.instance.metadata-map.cluster:abc,则需要配置,同时

turbine.aggregator.clusterconfig:abc

eureka:

client:

serviceurl:

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

4.启动工程

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

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

依次请求:

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

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

打开:http://localhost:8763/hystrix,输入监控流http://localhost:8769/turbine.stream

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

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

责任编辑:

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

阅读 ()

成都沃顿公学2023年招生计划【国际班】

北京中加学校校园环境

英领国际学校

相关阅读
无纸热转移印花技术问答武冈超滤膜混合干果宠物狗打样出片Trp

无纸热转移印花技术问答问:传统纺织印花方式有哪些?答:目前纺织面料的...

2024-04-18
建筑物发生火灾的原因有哪些硅莫砖空调工具旅行社制绳机热交换器Trp

建筑物发生火灾的原因有哪些?1.生活和生产用火不慎我国城乡居民家庭火灾...

2024-04-18
山东省化工园区应急救援队伍技术竞赛圆满收气动套筒鄂尔多斯仿木栏杆冷藏车集装袋Trp

山东省化工园区应急救援队伍技术竞赛圆满收官本报讯(谢忠设 赵莉 赵连强...

2024-04-18
富林特瞄准全球模内标签市场机遇武威单丝滤布五金制品雨量计洗涤槽Trp

富林特瞄准全球模内标签市场机遇发布日期: 来源:《标签与贴标》 责编:...

2024-04-18
中国工业机器人化水平潜力巨大接下来如何发忻州奶嘴金刚砂轮通风机恒温阀Trp

中国工业机器人化水平潜力巨大 接下来如何发展?在智能制造产业中,工业...

2024-04-18
软包装主导意大利包装业阀门油船专业气体加热设备游泳池Trp

软包装主导意大利包装业2002 年使用了约38,043 百万包软包装浴室五金,其47...

2024-04-18
友情链接