spring cloud之Turbine(九)

来源:互联网 发布:mac改变用户名 编辑:程序博客网 时间:2024/05/17 23:01

Turbine

在复杂的分布式系统中,相同服务的节点经常需要部署上百甚至上千个,很多时候,运维人员希望能够把相同服务的节点状态以一个整体集群的形式展现出来,这样可以更好的把握整个系统的状态。 为此,Netflix提供了一个开源项目(Turbine)来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。


建立一个hystrix--turbine模块

1、添加有关的依赖

<dependencies>      <dependency>          <groupId>org.springframework.cloud</groupId>          <artifactId>spring-cloud-starter-eureka</artifactId>      </dependency>      <!--spring-cloud-starter-eureka已经引了,所以可引可不引-->      <dependency>          <groupId>org.springframework.cloud</groupId>          <artifactId>spring-cloud-starter-ribbon</artifactId>      </dependency>     <!-- 断路器-->      <dependency>          <groupId>org.springframework.cloud</groupId>          <artifactId>spring-cloud-starter-hystrix</artifactId>      </dependency>      <!-- spring-boot-starter-actuator这个库让我们可以访问应用的很多信息,包括:/env、/info、/metrics、/health等。现在运行程序,然后在浏览器中访问:http://localhost:8080/health,-->      <dependency>          <groupId>org.springframework.boot</groupId>          <artifactId>spring-boot-starter-actuator</artifactId>      </dependency>      <!--Hystrix仪表板      Hystrix的主要优点之一是它收集关于每个HystrixCommand的一套指标。      Hystrix仪表板以有效的方式显示每个断路器的运行状况-->      <dependency>          <groupId>org.springframework.cloud</groupId>          <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>      </dependency>     <!-- turbine  把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。-->      <dependency>          <groupId>org.springframework.cloud</groupId>          <artifactId>spring-cloud-starter-turbine</artifactId>      </dependency>      <dependency>          <groupId>org.springframework.cloud</groupId>          <artifactId>spring-cloud-netflix-turbine</artifactId>      </dependency>      <dependency>          <groupId>org.springframework.boot</groupId>          <artifactId>spring-boot-starter-web</artifactId>      </dependency>  </dependencies>父pom.xml
    <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-test</artifactId>      <scope>test</scope>   </dependency><!--   spring-boot-starter-actuator这个库让我们可以访问应用的很多信息,   包括:/env、/info、/metrics、/health等。   现在运行程序,然后在浏览器中访问:http://localhost:8080/health,--><dependency>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-actuator</artifactId></dependency>

2、配置文件

#端口server.port=8091#设置eureka服务器所在的地址,查询服务和注册服务都需要依赖这个地址。eureka.client.serviceUrl.defaultZone=http\://localhost\:8081/eureka/#这在以后的服务与服务之间相互调用一般都是根据这个namespring.application.name=hystrix-dashboard-turbine# 心跳时间,即服务续约间隔时间(缺省为30s)eureka.instance.lease-renewal-interval-in-seconds= 5# 发呆时间,即服务续约到期时间(缺省为90s)eureka.instance.lease-expiration-duration-in-seconds=15     eurekaclientURL=http://EUREKA-CLIENT/hello?age=#配置Eureka中的serviceId列表,表明监控哪些服务turbine.appConfig=hystrix-service-turbine,hystrix-service#指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问turbine.aggregator.clusterConfig= defaultturbine.clusterNameExpression= new String("default")
  • turbine.appConfig :配置Eureka中的serviceId列表,表明监控哪些服务
  • turbine.aggregator.clusterConfig :指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问
  • turbine.clusterNameExpression : 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

3、启动类

启动类添加@EnableTurbine,激活对Turbine的支持

@SpringBootApplication//启用Hystrix仪表板@EnableHystrixDashboard//启动类添加@EnableTurbine,激活对Turbine的支持@EnableTurbinepublic class HystrixApplication {   public static void main(String[] args) {      SpringApplication.run(HystrixApplication.class, args);   }   }

到此Turbine(hystrix--turbine)配置完成

4、测试

启动两个使用了hystrix示例项目hystrix-service-turbine,hystrix-turbine

spring-cloud-consumer-node1项目改动如下:
application.properties文件内容分别为

#端口server.port=8085eureka.instance.hostname=localhost#设置eureka服务器所在的地址,查询服务和注册服务都需要依赖这个地址。eureka.client.serviceUrl.defaultZone=http\://localhost\:8081/eureka/#这在以后的服务与服务之间相互调用一般都是根据这个namespring.application.name=hystrix-service#eureka.client.register-with-eureka=true#eureka.client.fetch-registry=true# 心跳时间,即服务续约间隔时间(缺省为30s)eureka.instance.lease-renewal-interval-in-seconds= 5# 发呆时间,即服务续约到期时间(缺省为90s)eureka.instance.lease-expiration-duration-in-seconds=15     eurekaclientURL=http://EUREKA-CLIENT/hello?age=
#端口server.port=8092eureka.instance.hostname=localhost#设置eureka服务器所在的地址,查询服务和注册服务都需要依赖这个地址。eureka.client.serviceUrl.defaultZone=http\://localhost\:8081/eureka/#这在以后的服务与服务之间相互调用一般都是根据这个namespring.application.name=hystrix-service-turbine#eureka.client.register-with-eureka=true#eureka.client.fetch-registry=true# 心跳时间,即服务续约间隔时间(缺省为30s)eureka.instance.lease-renewal-interval-in-seconds= 5# 发呆时间,即服务续约到期时间(缺省为90s)eureka.instance.lease-expiration-duration-in-seconds=15     eurekaclientURL=http://EUREKA-CLIENT/hello?age=


打开eureka后台可以看到注册了三个服务:


访问 http://localhost:8091/turbine.stream

返回:

: pingdata: {"reportingHostsLast10Seconds":2,"name":"meta","type":"meta","timestamp":1512354379389}data: {"currentCorePoolSize":10,"currentLargestPoolSize":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"currentActiveCount":0,"currentMaximumPoolSize":10,"currentQueueSize":0,"type":"HystrixThreadPool","currentTaskCount":18,"currentCompletedTaskCount":18,"rollingMaxActiveThreads":0,"rollingCountCommandRejections":0,"name":"HelloService","reportingHosts":1,"currentPoolSize":10,"propertyValue_queueSizeRejectionThreshold":5,"rollingCountThreadsExecuted":0}

并且会不断刷新以获取实时的监控数据,说明和单个的监控类似,返回监控项目的信息。进行图形化监控查看,输入:http://localhost:8091/hystrix,返回酷酷的小熊界面,输入:http://localhost:8091/turbine.stream,然后点击 Monitor Stream ,可以看到出现了俩个监控列表


原文:https://www.cnblogs.com/ityouknow/p/6889059.html