how2j.cn

下载区
文件名 文件大小
springcloud.rar 74k
步骤 1 : 需求   
步骤 2 : 先运行,看到效果,再学习   
步骤 3 : 模仿和排错   
步骤 4 : 创建子项目   
步骤 5 : pom.xml   
步骤 6 : ProductServiceTurbineApplication   
步骤 7 : application.yml   
步骤 8 : AccessViewService   

在上个知识点讲解了针对一个微服务的断路器监控,但是微服务通常会是多个实例组成的一个集群。 倘若集群里的实例比较多,难道要挨个挨个去监控这些实例吗? 何况有时候,根据集群的需要,会动态增加或者减少实例,监控起来就更麻烦了。
所以为了方便监控集群里的多个实例,springCloud 提供了一个 turbine 项目,它的作用是把一个集群里的多个实例汇聚在一个 turbine里,这个然后再在 断路器监控里查看这个 turbine, 这样就能够在集群层面进行监控啦。
需求
步骤 2 :

先运行,看到效果,再学习

edit
老规矩,先下载右上角的可运行项目,配置运行起来,确认可用之后,再学习做了哪些步骤以达到这样的效果。
1. 首先挨个运行 EurekaServerApplication, ConfigServerApplication, ProductDataServiceApplication, ProductViewServiceFeignApplication:8012,, ProductViewServiceFeignApplication:8013,ProductServiceHystrixDashboardApplication, ProductServiceTurbineApplication.
2. 运行视图微服务里的 AccessViewService 来周期性地访问 http://127.0.0.1:8012/products 和 http://127.0.0.1:8013/products。 因为只有访问了,监控里才能看到数据。
3. 打开监控地址
http://localhost:8020/hystrix
4. 在最上面输入
http://localhost:8021/turbine.stream

这个地址就是汇聚了8012,8013 两个视图微服务 turbine聚合信息。
5. 然后点击 Monitor Stream 就可以看到监控信息了。
先运行,看到效果,再学习
在确保可运行项目能够正确无误地运行之后,再严格照着教程的步骤,对代码模仿一遍。
模仿过程难免代码有出入,导致无法得到期望的运行结果,此时此刻通过比较正确答案 ( 可运行项目 ) 和自己的代码,来定位问题所在。
采用这种方式,学习有效果,排错有效率,可以较为明显地提升学习速度,跨过学习路上的各个槛。

推荐使用diffmerge软件,进行文件夹比较。把你自己做的项目文件夹,和我的可运行项目文件夹进行比较。
这个软件很牛逼的,可以知道文件夹里哪两个文件不对,并且很明显地标记出来
这里提供了绿色安装和使用教程:diffmerge 下载和使用教程
创建子项目
一堆jar
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>cn.how2j.springcloud</groupId> <artifactId>springcloud</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>productServiceTurbine</artifactId> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-turbine</artifactId> </dependency> </dependencies> </project>
步骤 6 :

ProductServiceTurbineApplication

edit
启动类,主要是注解:@EnableTurbine
package cn.how2j.springcloud; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.netflix.turbine.EnableTurbine; import cn.hutool.core.util.NetUtil; @SpringBootApplication @EnableTurbine public class ProductServiceTurbineApplication { public static void main(String[] args) { int port = 8021; if(!NetUtil.isUsableLocalPort(port)) { System.err.printf("端口%d被占用了,无法启动%n", port ); System.exit(1); } new SpringApplicationBuilder(ProductServiceTurbineApplication.class).properties("server.port=" + port).run(args); } }
配置信息,主要是:

appConfig: product-view-service-feign

这就表示它会把所有微服务名称是product-view-service-feign 的实例信息都收集起来。
spring: application.name: turbine turbine: aggregator: clusterConfig: default appConfig: product-view-service-feign ### 配置Eureka中的serviceId列表,表明监控哪些服务 clusterNameExpression: new String("default") eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/
spring:
  application.name: turbine
turbine:
  aggregator:
    clusterConfig: default   
  appConfig: product-view-service-feign  ### 配置Eureka中的serviceId列表,表明监控哪些服务
  clusterNameExpression: new String("default")
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
步骤 8 :

AccessViewService

edit
修改一下AccessViewService, 使得其访问 8012和 8013端口
package cn.how2j.springcloud.util; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.http.HttpUtil; public class AccessViewService { public static void main(String[] args) { while(true) { ThreadUtil.sleep(1000); access(8012); access(8013); } } public static void access(int port) { try { String html= HttpUtil.get(String.format("http://127.0.0.1:%d/products",port)); System.out.printf("%d 地址的视图服务访问成功,返回大小是 %d%n" ,port, html.length()); } catch(Exception e) { System.err.printf("%d 地址的视图服务无法访问%n",port); } } }


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


问答区域    
2020-11-23 突然发现zipkin
549414168




站长,在这一步访问了一下服务链路追踪,发现有两个报错应该怎么解决这个呢,消息总线bus那章还测试的没有问题
加载中

							

							





回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2020-08-20 没有明显看出来两个视图微服务聚合以后在仪表盘被监控和一个视图服务器的区别,host是2,也无法切换,聚合以后怎么查看每一个
fas

如题







回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2020-08-07 玩不动了 16G内存,就开一个IDEA,跑不动,太难了
2020-04-01 一直Loading有人也是这种情况吗




提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 分布式和集群-SpringCloud-断路器聚合监控 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 578362961
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图