SpringCloud Hystrix Dashboard

server 端

pom

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            <version>2.2.9.RELEASE</version>
        </dependency>

启动类

@SpringBootApplication
@EnableHystrixDashboard
public class SpringbootHystrixApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootHystrixApplication.class, args);
    }

}

配置文件

server:
  port: 8089

spring:
  application:
    name: ludb-hystrix #应用名称

eureka:
  instance:
    prefer-ip-address: true #是否使用IP地址注册(用于eureka展示)
    instance-id:  ${spring.cloud.client.ip-address}:${server.port} #当前客户端IP:端口
  client:
    service-url: #设置服务注册中心地址【向注册中心集群注册(注册两台是为了防止第一台宕机还可以挂在第2台上)】
      defaultZone: http://ludb:ludb123@localhost:8761/eureka/,http://ludb:ludb123@localhost:8762/eureka/

    registry-fetch-interval-seconds: 10 #表示10秒拉取一次服务注册信息,默认30秒
    register-with-eureka: true #是否将自己注册到注册中心,默认true

#默认情况下大多数端点都没有通过 http 公开,我们公开了所有端点,以便SpringAdmin访问
management:
  endpoint.health.show-details: always
  endpoints:
    web:
      exposure:
        include: '*'

hystrix:
  dashboard:
    proxy-stream-allow-list: localhost

client端

pom文件

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            <version>2.2.9.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

config

package com.eurekaclient3.config;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
public class HystrixConfig {
    @Bean
    public ServletRegistrationBean getServlet(){
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值