国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Java > 正文

Spring Cloud之服務監控turbine的示例

2024-07-14 08:40:33
字體:
來源:轉載
供稿:網友

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@EnableHystrixDashboardpublic 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: turbineserver: port: 8000turbine: 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: helloserver: port: 9001eureka: 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: 3logging: 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: helloClientserver: port: 20000eureka: 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: 3logging: 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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到JAVA教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肇庆市| 柏乡县| 玉溪市| 安吉县| 濮阳县| 九江市| 普安县| 大田县| 吉木萨尔县| 佛冈县| 互助| 高唐县| 南阳市| 绵竹市| 格尔木市| 杭锦后旗| 双辽市| 凯里市| 长沙县| 安义县| 晴隆县| 洪洞县| 乌苏市| 辰溪县| 四子王旗| 株洲县| 四川省| 汽车| 临清市| 贺州市| 大竹县| 黔西县| 北海市| 青海省| 安多县| 资溪县| 白河县| 于田县| 额敏县| 玉龙| 固原市|