在第四篇文章断路器讲述了如何使用断路器,并简单的介绍了下Hystrix Dashboard组件,这篇文章更加详细的介绍Hystrix Dashboard。web
1、Hystrix Dashboard简介
在微服务架构中为例保证程序的可用性,防止程序出错致使网络阻塞,出现了断路器模型。断路器的情况反应了一个程序的可用性和健壮性,它是一个重要指标。了解springcloud架构能够加求求:三五三六二四七二五九,Hystrix Dashboard是做为断路器状态的一个组件,提供了数据监控和友好的图形化界面。spring
2、准备工做
本文的的来源于第一篇文章的栗子,在它的基础上进行改造。网络
3、开始改造service-hi
在pom的工程文件引入相应的依赖:架构
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> </dependencies>
其中,这三个依赖是必须的,缺一不可。app
在程序的入口ServiceHiApplication类,加上@EnableHystrix注解开启断路器,这个是必须的,而且须要在程序中声明断路点HystrixCommand;加上@EnableHystrixDashboard注解,开启HystrixDashboard分布式
@SpringBootApplication @EnableEurekaClient @EnableDiscoveryClient @RestController @EnableHystrix @EnableHystrixDashboard @EnableCircuitBreaker public class ServiceHiApplication { /** * 访问地址 http://localhost:8762/actuator/hystrix.stream * @param args */ public static void main(String[] args) { SpringApplication.run( ServiceHiApplication.class, args ); } @Value("${server.port}") String port; @RequestMapping("/hi") @HystrixCommand(fallbackMethod = "hiError") public String home(@RequestParam(value = "name", defaultValue = "forezp") String name) { return "hi " + name + " ,i am from port:" + port; } public String hiError(String name) { return "hi,"+name+",sorry,error!"; } }
运行程序: 依次开启eureka-server 和service-hi.ide
4、Hystrix Dashboard图形展现
打开http://localhost:8762/actuator/hystrix.stream,能够看到一些具体的数据:
打开localhost:8762/hystrix 能够看见如下界面:
在界面依次输入:http://localhost:8762/actuator/hystrix.stream 、2000 、miya
;点肯定。spring-boot
在另外一个窗口输入: http://localhost:8762/hi?name=forezp微服务
从新刷新hystrix.stream网页,你会看到良好的图形化界面:.ui