我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

SpringCloudturbine监控实现过程解析

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

成都创新互联公司是专业的库伦网站建设公司,库伦接单;提供成都网站制作、成都网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行库伦网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

1、pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>

  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);
    registrationBean.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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。


新闻标题:SpringCloudturbine监控实现过程解析
当前地址:http://shouzuofang.com/article/gcpdpc.html

其他资讯