Spring Cloud之服務(wù)監(jiān)控turbine的示例
turbine是聚合服務(wù)器發(fā)送事件流數(shù)據(jù)的一個(gè)工具,hystrix的監(jiān)控中,只能監(jiān)控單個(gè)節(jié)點(diǎn),實(shí)際生產(chǎn)中都為集群,因此可以通過(guò)turbine來(lái)監(jiān)控集群下hystrix的metrics情況,通過(guò)eureka來(lái)發(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/
啟動(dòng)服務(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
啟動(dòng)項(xiàng)目
訪問(wèn) localhost:8000/hystrixx 可以看到頁(yè)面
注: turbine只能監(jiān)控hystrix服務(wù),不是hystrix服務(wù),不能監(jiān)控,如 hello這個(gè)服務(wù)雖然配置了集群,但是沒(méi)有使用hystrix,所以不會(huì)受監(jiān)控。
項(xiàng)目地址 https://github.com/luosai001/Spring-Cloud-Sample/tree/master
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Boot實(shí)現(xiàn)郵件發(fā)送必會(huì)的5種姿勢(shì)
這篇文章主要給大家介紹了關(guān)于Spring Boot實(shí)現(xiàn)郵件發(fā)送必會(huì)的5種姿勢(shì),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
struts1之簡(jiǎn)單mvc示例_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了struts1之簡(jiǎn)單mvc示例的相關(guān)資料,需要的朋友可以參考下2017-09-09
java中request對(duì)象各種方法的使用實(shí)例分析
這篇文章主要介紹了java中request對(duì)象各種方法的使用,結(jié)合完整實(shí)例形式較為詳細(xì)的分析了request對(duì)象的功能及其常用方法的使用技巧,需要的朋友可以參考下2015-12-12
Spring Boot中使用Activiti的方法教程(二)
工作流(Workflow),就是“業(yè)務(wù)過(guò)程的部分或整體在計(jì)算機(jī)應(yīng)用環(huán)境下的自動(dòng)化”,下面這篇文章主要給大家介紹了關(guān)于Spring Boot中使用Activiti的相關(guān)資料,需要的朋友可以參考下2018-08-08
SpringBoot部署到外部Tomcat無(wú)法注冊(cè)到Nacos服務(wù)端的解決思路
這篇文章主要介紹了SpringBoot部署到外部Tomcat無(wú)法注冊(cè)到Nacos服務(wù)端,本文給大家分享完美解決思路,結(jié)合實(shí)例代碼給大家講解的非常詳細(xì),需要的朋友可以參考下2023-03-03
Java使用cookie顯示最近查看過(guò)的書(shū)
這篇文章主要為大家詳細(xì)介紹了Java使用cookie顯示最近查看過(guò)的書(shū),感興趣的小伙伴們可以參考一下2016-04-04

