hystrix dashboard

依赖

父版本

<spring-boot.version>2.1.6.RELEASE</spring-boot.version>
    <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>

子模块
1.hystrix-dashboard模块 不用注册到eureka,

<!--web 模块 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		
spring:
  application:
    name: cloud-hystrix-dashboard
server: 
  port: 52001
    
hystrix:
  dashboard:
    proxy-stream-allow-list: "localhost"
    
#management.endpoints.web.exposure.include=hystrix.stream
#降级熔断hystrix
management:
  endpoints:
    web:
      exposure:
        include: "*" #暴露所有
@EnableHystrixDashboard
@SpringBootApplication
public class DashboardApplication {

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

}

消费者模块:
其他业务不说,只要是controller请求就行

<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
	</dependency>
  		
	  <dependency>
	 	 <groupId>org.springframework.boot</groupId>
	 	 <artifactId>spring-boot-starter-actuator</artifactId>
	  </dependency> 
# 使用Hystrix 
management:
  endpoints: 
    web:
      exposure: 
        include: "*"
        
#开启feign支持hystrix,默认关闭
#feign:
#  hystrix:
#    enabled: true

启动类

@EnableFeignClients
@EnableEurekaClient
//@SpringBootApplication
@SpringCloudApplication
@MapperScan("com.josion.seckill.mapper")
public class SeckillApplication {
	
	public static void main(String[] args) {
		
		SpringApplication.run(SeckillApplication.class, args);
		
	}
	
	@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;
	}

}

Controller类

@RestController
@RequestMapping("/user")
//@DefaultProperties(defaultFallback = "fallBack") // 统一写整个类的回退方法
public class UserController {	
@HystrixCommand(fallbackMethod = "findByIdFallback") //单独写回退方法
	@GetMapping("/feign-wares/list")
	//这个方法含有什么参,回退的方法就含什么参
	public String feignWares() {
		
		String waresFeign = userService.waresFeign();
		
		return waresFeign;
	}
	
	//回退时执行的方法
	public String findByIdFallback(){
	    return "失败了。。。";
	}
}

测试:
#hystrix-dashborad测试
第一步: http://localhost:52001/hystrix
在这里插入图片描述

	第二步: 地址框中输入
		   http://localhost:58080/seckill/actuator/hystrix.stream
	第三步: 请求这个地址	
		   http://localhost:9527/seckill/user/feign-wares/list

在这里插入图片描述

错误:

浏览器F12 没有任何报错的信息

如果直接访问http://localhost:58082/hystrix.stream 则界面一直会打印ping,但没有结果返回:

这个Loading…是一直在等待负载均衡的提供方要去消费服务,即访问负载均衡服务器,去调用客户端,如果有数据响应则监控界面就会有图形数据展示:

如果想让图中的数据发生变化,则需要循环多次的去访问负载均衡的提供方,让其消费服务,以至于达到监控的目的。
hystrix-dashborad服务请求 http://localhost:52001/actuator 没问题
http://localhost:52001/hystrix.stream没问题
http://localhost:52001/actuator/hystrix.stream报错404
解决:spring cloud 2.x 中hystrix没有/actuator/hystrix.stream路径而报错Unable to connect to Command Metric Stream

1.启动类上添加以下注解

@SpringCloudApplication
@EnableHystrixDashboard

因为@SpringCloudApplication包括@SpringBootApplication、@EnableDiscoveryClient、@EnableCircuitBreaker
启动类中添加以下代码

	@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;
	}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值