内容简介:上一篇介绍了 Hystrix Dashboard 监控单体应用的例子,在生产环境中,监控的应用往往是一个集群,我们需要将每个实例的监控信息聚合起来分析,这就用到了 Turbine 工具。Turbine有一个重要的功能就是汇聚监控信息,并将汇聚到的监控信息提供给Hystrix Dashboard来集中展示和监控。
简介
上一篇介绍了 Hystrix Dashboard 监控单体应用的例子,在生产环境中,监控的应用往往是一个集群,我们需要将每个实例的监控信息聚合起来分析,这就用到了 Turbine 工具。Turbine有一个重要的功能就是汇聚监控信息,并将汇聚到的监控信息提供给Hystrix Dashboard来集中展示和监控。
流程
实验
工程说明
| 工程名 | 端口 | 作用 |
|---|---|---|
| eureka-server | 8761 | 注册中心 |
| service-hi | 8762 | 服务提供者 |
| service-consumer | 8763 | 服务消费者 |
| service-turbine | 8765 | Turbine服务 |
核心代码
eureka-server 、service-hi、service-consumer 工程代码与上一节 微服务熔断限流Hystrix之Dashboard 相同,下面是 service-turbine 工程的核心代码。
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</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>
application.yml
server:
port: 8765
spring:
application:
name: service-turbine
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
turbine:
app-config: service-consumer
cluster-name-expression: new String("default")
combine-host-port: true
参数说明:
-
turbine.app-config:指定要监控的应用名
-
turbine.cluster-name-expression:指定集群的名字
-
turbine.combine-host-port:表示同一主机上的服务通过host和port的组合来进行区分,默认情况下是使用host来区分,这样会使本地调试有问题
启动类
@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableTurbine
public class ServiceTurbineApplication {
public static void main(String[] args) {
SpringApplication.run( ServiceTurbineApplication.class, args );
}
}
模拟多实例
启动多个 service-consumer 工程,来模拟多实例,可以通过命令java -jar service-consumer.jar --server.port=XXXX 来实现。
为了方便,在编辑器中实现启动工程。但 idea 不支持单个应用的多次启动, 需要开启并行启动:
选择 “Edit Configurations...”
勾选 “Allow running in parallel”
测试
启动工程,访问 http//localhost:8763/hi , http//localhost:8764/hi , http//localhost:8763/oh , http//localhost:8764/oh,来产生测试数据。
访问 http://localhost:8765/hystrix ,
输入监控流地址 http://localhost:8765/turbine.stream ,点击 Monitor Stream 进入监控页面
可以看到聚合了两个实例的 Hystrix dashbord 数据。
源码
https://github.com/gf-huanchupk/SpringCloudLearning/tree/master/chapter18
-- END --
每一个“ 在 看 ”,都是对我最大的肯定 !
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
从零开始学创业大全集
阳飞扬 / 中国华侨出版社 / 2011-10-1 / 29.80元
为了让每一个怀揣梦想走上创业之路的有志者能在最短的时间内叩开创业的大门,了解创业的流程和方法,从而找到适合自己的创业之路,我们精心编写了这本《从零开始学创业大全集》。阳飞扬编著的《从零开始学创业大全集(超值白金版)》从创业准备、创业团队的组建、创业项目和商业模式的选择、创业计划书的制作、创业资金的筹集、企业的经营策略、资本运作以及产品营销方法、危机应对策略等方面,全面系统地阐述了创业的基本理论与实......一起来看看 《从零开始学创业大全集》 这本书的介绍吧!