SpringCloud turbine监控实现过程解析

网友投稿 282 2022-12-17


SpringCloud turbine监控实现过程解析

这篇文章主要介绍了SpringCloud turbine监控实现过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

1、pom.xml文件

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.test

springcloud

1.0-SNAPSHOT

../

com.test

eureka-client-comsumer-feign-hystrix-turbine

0.0.1-SNAPSHOT

eureka-client-comsumer-feign-hystrix-turbine

Demo project for Spring Boot

1.8

Greenwich.SR1

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-netflix-hystrix-dashboard

org.springframework.boot

spring-boot-starter-actuator

org.springframework.cloud

spring-cloud-starter-netflix-eureka-client

org.springframework.cloud

spring-cloud-starter-netflix-hystrix

org.springframework.cloud

spring-cloud-starter-netflix-turbine

org.springframework.cloud

spring-cloud-starter-openfeign

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine

org.springframework.cloud

spring-cloud-dependencies

${spring-cloud.version}

pom

import

org.springframework.boot

spring-boot-maven-plugin

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.test

springcloud

1.0-SNAPSHOT

../

com.test

eureka-client-comsumer-feign-hystrix-turbine

0.0.1-SNAPSHOT

eureka-client-comsumer-feign-hystrix-turbine

Demo project for Spring Boot

1.8

Greenwich.SR1

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-netflix-hystrix-dashboard

org.springframework.boot

spring-boot-starter-actuator

org.springframework.cloud

spring-cloud-starter-netflix-eureka-client

org.springframework.cloud

spring-cloud-starter-netflix-hystrix

org.springframework.cloud

spring-cloud-starter-netflix-turbine

org.springframework.cloud

spring-cloud-starter-openfeign

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine

org.springframework.cloud

spring-cloud-dependencies

${spring-cloud.version}

pom

import

org.springframework.boot

spring-boot-maven-plugin

主要添加了一下几个依赖:

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-netflix-hystrix-dashboard

org.springframework.boot

spring-boot-starter-actuator

org.springframework.cloud

spring-cloud-starter-netflix-eureka-client

org.springframework.cloud

spring-cloud-starter-netflix-hystrix

org.springframework.cloud

spring-cloud-starter-netflix-turbine

org.springframework.cloud

spring-cloud-starter-openfeign

2、添加注解

package com.test.eurekaclientcomsumerfeignhystrixturbine;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsstreamServlet;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.web.servlet.ServletRegistrationBean;

import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

import org.springframework.cloud.netflix.turbine.EnableTurbine;

import org.springframework.cloud.openfeign.EnableFeignClients;

import org.springframework.context.annotation.Bean;

@SpringBootApplication

@EnableEurekaClient

@EnableFeignClients

@EnableCircuitBreaker

@EnableTurbine

@EnableHystrixDashboard

/**

* Dashboard访问地址:http://localhost:7016/hystrix

* 在Dashboard输入 http://localhost:7016/turbine.stream

*/

public class EurekaClientComsumerFeignHystrixTurbineApplication {

@Bean

public ServletRegistrationBean getServlet(){

HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();

ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);

registrationgwjvYZsMWpBean.setLoadOnStartup(1);

registrationBean.addUrlMappings("/actuator/hystrix.stream");

registrationBean.setName("HystrixMetricsStreamServlet");

return registrationBean;

}

public static void main(String[] args) {

SpringApplication.run(EurekaClientComsumerFeignHystrixTurbineApplication.class, args);

}

}

3、application.yml文件配置

server:

port: 7016

spring:

application:

name: eureka-client-feign-hystrix-turbine

eureka:

instance:

hostname: localhost

prefer-ip-address: true

instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}

client:

serviceUrl:

defaultZone: http://${eureka.instance.hostname}:8761/eureka

eureka-provider: #远程服务虚拟主机名

ribbon:

NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RoundRobinRule

#turbine配置

turbine:

aggregator:

cluster-config: default

app-config: eureka-client-feign-hystrix-turbine,eureka-client-feign-hystrix,eureka-client-feign-hystrix-dashboard

cluster-name-expression: "'default'"

4、访问

a)http://localhost:7016/hystrix

b)在dashboard输入:http://localhost:7016/turbine.stream

具体的代码可访问 github:https://github.com/812406210/springCloud.git


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Spring Boot优雅使用RocketMQ的方法实例
下一篇:springboot redis分布式锁代码实例
相关文章

 发表评论

暂时没有评论,来抢沙发吧~