Spring Cloud 之服务监控 turbine(六)

17 篇文章 0 订阅
8 篇文章 0 订阅


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"?>
<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>

    <artifactId>turbine</artifactId>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <dependencies>
        <!-- hystrix依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
        </dependency>
        <!-- turnbine依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-turbine</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

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依赖包


<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>



同理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 如果对您有帮助,请点赞,谢谢。

     

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值