1. 程式人生 > >spring cloud: Hystrix(七):Hystrix的斷容器監控dashboard

spring cloud: Hystrix(七):Hystrix的斷容器監控dashboard

exec adb comm 分享圖片 variable res for 返回 -h

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