溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Spring Cloud之服務(wù)監(jiān)控turbine的示例

發(fā)布時(shí)間:2020-10-13 10:18:20 來源:腳本之家 閱讀:189 作者:冰清雪酷 欄目:編程語言

turbine是聚合服務(wù)器發(fā)送事件流數(shù)據(jù)的一個(gè)工具,hystrix的監(jiān)控中,只能監(jiān)控單個(gè)節(jié)點(diǎn),實(shí)際生產(chǎn)中都為集群,因此可以通過turbine來監(jiān)控集群下hystrix的metrics情況,通過eureka來發(fā)現(xiàn)hystrix服務(wù)。

新建turbine項(xiàng)目

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 ##需要監(jiān)控的服務(wù)名
 aggregator:
 clusterConfig: main ##需要監(jiān)控的服務(wù)集群名
 clusterNameExpression: metadata['cluster']

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

啟動服務(wù)

helloserviceeureka 項(xiàng)目 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 項(xiàng)目 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

啟動項(xiàng)目

訪問 localhost:8000/hystrixx 可以看到頁面

注: turbine只能監(jiān)控hystrix服務(wù),不是hystrix服務(wù),不能監(jiān)控,如 hello這個(gè)服務(wù)雖然配置了集群,但是沒有使用hystrix,所以不會受監(jiān)控。

項(xiàng)目地址 https://github.com/luosai001/Spring-Cloud-Sample/tree/master

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI