zoukankan      html  css  js  c++  java
  • spring cloud: Hystrix(七):Hystrix的断容器监控dashboard

    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 的指示图就发生变化

  • 相关阅读:
    UVA11367 Full Tank?
    不均衡样本集问题
    NLP interview
    Linux 指令
    Python 趣题
    Grid Illumination
    动态规划-Minimum Cost to Merge Stones
    Contest 141
    Python join()方法
    Single Number
  • 原文地址:https://www.cnblogs.com/achengmu/p/9912080.html
Copyright © 2011-2022 走看看