码迷,mamicode.com
首页 > 编程语言 > 详细

spring cloud: Hystrix(七):Hystrix的断容器监控dashboard

时间:2018-11-05 22:52:14      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:文件引入   adb   访问   main   iso   boot   temp   pat   nbsp   

Hystrix的断容器监控dashboard。

dashboard是用来监控Hystrix的断容器监控的,图形化dashboard是如何实现指标的收集展示的。

dashboard

本地端口8730

项目地址:http://localhost:8730/hystrix

在Pom.xml文件引入:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>	

  

在入口文件开启注解

@SpringBootApplication

@EnableHystrixDashboard
@SpringBootApplication
public class FeignApp {


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

  

然后运行,http://localhost:8730/hystrix

 

Hystrix

本项目地址:http://192.168.1.6:8010

pom.xml加入hystrix引入

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>

  

入口文件引入hystrix注解

@EnableCircuitBreake

@EnableEurekaClient
@SpringBootApplication
//hystrix
@EnableCircuitBreaker
public class HystrixApplication {	
	
	//ribbon
	@Bean
	@LoadBalanced
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}

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

  

Controller文件调用hystrix

@HystrixCommand(fallbackMethod = "notfindback", commandProperties=@HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE") )

其中fallbackMethod 方法是回退,当网络不通,或者无法访问时访问:notfindback方法,返回默认值

commandProperties是合并线程

@RestController
public class MovieController {

	@Autowired
	private RestTemplate restTemplate;	
	
	
	@GetMapping("/movie/{id}")
	@HystrixCommand(fallbackMethod = "notfindback", commandProperties=@HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE") )
	public User findById(@PathVariable Long id)
	{
		//http://localhost:7900/simple/
		return restTemplate.getForObject("http://spring-boot-user/simple/" + id, User.class);
	}
	
	public User notfindback(Long id)
	{
		User user = new User();
		user.setId(0L);
		return user;
		
	}
	
}

  

访问:

http://192.168.1.6:8010/movie/1

查看hystrix.stream信息

http://192.168.1.6:8010/hystrix.stream

 

dashboard监控http://192.168.1.6:8010/hystrix.stream信息

在http://localhost:8730/hystrix中输入要监控的hystrix.stream

技术分享图片

 

如下

技术分享图片

 

每当我刷新:http://192.168.1.6:8010/movie/1数据时,http://localhost:8730/hystrix/monitor?stream=http%3A%2F%2F192.168.1.6%3A8010%2Fhystrix.stream 的指示图就发生变化

 

spring cloud: Hystrix(七):Hystrix的断容器监控dashboard

标签:文件引入   adb   访问   main   iso   boot   temp   pat   nbsp   

原文地址:https://www.cnblogs.com/achengmu/p/9912080.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!