Spring Cloud之服务监控turbine的示例
程序员文章站
2023-12-02 20:53:46
turbine是聚合服务器发送事件流数据的一个工具,hystrix的监控中,只能监控单个节点,实际生产中都为集群,因此可以通过turbine来监控集群下hystrix的me...
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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
推荐阅读
-
spring cloud 的监控turbine-rabbitmq的示例
-
Spring Cloud之服务监控turbine的示例
-
spring cloud之Turbine断路器聚合监控(十二)
-
spring-cloud学习之eureka-server服务注册中心的高可用
-
Spring Cloud(Finchley.RELEASE版本)微服务学习实践:4.3Hystrix监控数据集群-Turbine
-
spring cloud之Turbine断路器聚合监控(十二)
-
详细介绍C#服务器性能监控之性能计数器的代码示例
-
C#服务器性能监控之WMI的代码示例详解
-
详细介绍C#服务器性能监控之性能计数器的代码示例
-
C#服务器性能监控之WMI的代码示例详解