资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

SpringCloud之服务监控turbine的示例

turbine是聚合服务器发送事件流数据的一个工具,hystrix的监控中,只能监控单个节点,实际生产中都为集群,因此可以通过turbine来监控集群下hystrix的metrics情况,通过eureka来发现hystrix服务。

创新互联建站专业为企业提供青山湖网站建设、青山湖做网站、青山湖网站设计、青山湖网站制作等企业网站建设、网页设计与制作、青山湖企业网站模板建站服务,十余年青山湖做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

新建turbine项目

TurbineApplication.java

package turbine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
/**
 * Created by sai.luo on 2017/4/26.
 */
@SpringBootApplication
@EnableTurbine
@EnableHystrix
@EnableHystrixDashboard
public class TurbineApplication{
 public static void main(String[] args) {
  SpringApplication.run(TurbineApplication.class,args);
 }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

 4.0.0

 turbine
 
  UTF-8
  1.8
 

 
  org.springframework.boot
  spring-boot-starter-parent
  1.5.2.RELEASE
   
 

 
  
  
   org.springframework.cloud
   spring-cloud-starter-hystrix
  
  
   org.springframework.cloud
   spring-cloud-starter-hystrix-dashboard
  
  
  
   org.springframework.cloud
   spring-cloud-starter-turbine
  
 
 
  
   
    org.springframework.cloud
    spring-cloud-dependencies
    Camden.SR5
    pom
    import
   
  
 

 
  
   
    org.springframework.boot
    spring-boot-maven-plugin
   
  
 

application.yml

spring:
 application:
 name: turbine
server:
 port: 8000
turbine:
 app-config: hello,helloClient ##需要监控的服务名
 aggregator:
 clusterConfig: main ##需要监控的服务集群名
 clusterNameExpression: metadata['cluster']

eureka:
 instance:
 preferIpAddress: true
 statusPageUrlPath: /info.html
 client:
 serviceUrl:
  defaultZone: http://localhost:8761/eureka/

启动服务

helloserviceeureka 项目 appliation.yml 增加集群配置

更改为

spring:
 application:
 name: hello

server:
 port: 9001

eureka:
 instance:
 lease-renewal-interval-in-seconds: 3
 lease-expiration-duration-in-seconds: 5
 metadata-map:
  cluster: main
 client:
 serviceUrl:
  defaultZone: http://localhost:8761/eureka/
 registry-fetch-interval-seconds: 3

logging:
 level:
 com:
  netflix:
  eureka: OFF
  discovery: OFF

pom.xml增加hystrix依赖包


 org.springframework.cloud
 spring-cloud-starter-hystrix

同理ribboneureka 项目 application.yml 增加集群配置

更改后如下

spring:
 application:
 name: helloClient

server:
 port: 20000

eureka:
 instance:
 lease-renewal-interval-in-seconds: 3
 lease-expiration-duration-in-seconds: 5
 metadata-map:
  cluster: main
 client:
 serviceUrl:
  defaultZone: http://localhost:8761/eureka/
 registry-fetch-interval-seconds: 3

logging:
 level:
 com:
  netflix:
  eureka: OFF
  discovery: OFF

pom.xml增加hystrix依赖包

RibbonEurekaApplication.java 增加注解

@EnableHystrix

启动项目

访问 localhost:8000/hystrixx 可以看到页面

注: turbine只能监控hystrix服务,不是hystrix服务,不能监控,如 hello这个服务虽然配置了集群,但是没有使用hystrix,所以不会受监控。

项目地址 https://github.com/luosai001/Spring-Cloud-Sample/tree/master

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。


网站名称:SpringCloud之服务监控turbine的示例
当前URL:http://cdkjz.cn/article/gpdcii.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220