Spring Cloud之服務(wù)監(jiān)控turbine的示例
turbine是聚合服務(wù)器發(fā)送事件流數(shù)據(jù)的一個工具,hystrix的監(jiān)控中,只能監(jiān)控單個節(jié)點,實際生產(chǎn)中都為集群,因此可以通過turbine來監(jiān)控集群下hystrix的metrics情況,通過eureka來發(fā)現(xiàn)hystrix服務(wù)。
新建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 ##需要監(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 項目 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只能監(jiān)控hystrix服務(wù),不是hystrix服務(wù),不能監(jiān)控,如 hello這個服務(wù)雖然配置了集群,但是沒有使用hystrix,所以不會受監(jiān)控。
項目地址 https://github.com/luosai001/Spring-Cloud-Sample/tree/master
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
spring boot2.0實現(xiàn)優(yōu)雅停機(jī)的方法
這篇文章主要介紹了spring boot2.0實現(xiàn)優(yōu)雅停機(jī)的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05springBoot 項目排除數(shù)據(jù)庫啟動方式
這篇文章主要介紹了springBoot 項目排除數(shù)據(jù)庫啟動方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-09-09java-SSH2實現(xiàn)數(shù)據(jù)庫和界面的分頁
本文主要是介紹SSH2實現(xiàn)數(shù)據(jù)庫和界面的分頁的代碼,分頁在web應(yīng)用中是經(jīng)常要做的事情,實用性比較大,有需要的朋友可以來了解一下。2016-10-10Java中的List和MySQL中的varchar相互轉(zhuǎn)換的解決方案
實體類中有一個 List<String> 類型的屬性,對應(yīng)于 MySQL 表里的 varchar 字段,使用 MyBatis 添加或查詢時能互相轉(zhuǎn)換,本文給大家介紹Java中的List和MySQL中的varchar相互轉(zhuǎn)換的解決方案,需要的朋友可以參考下2024-06-06詳解Java編程規(guī)約(命名風(fēng)格、常量定義、代碼格式)
這篇文章主要介紹了詳解Java編程規(guī)約(命名風(fēng)格、常量定義、代碼格式),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-10-10Java數(shù)據(jù)結(jié)構(gòu)之KMP算法詳解以及代碼實現(xiàn)
KMP算法是一種改進(jìn)的字符串匹配算法,核心是利用之前的匹配失敗時留下的信息,選擇最長匹配長度直接滑動,從而減少匹配次數(shù)。本文主要介紹了KMP算法的原理與實現(xiàn),需要的可以參考一下2022-12-12