这篇文章主要介绍”SpringCloud怎么实现断路器监控”,在日常操作中,相信很多人在SpringCloud怎么实现断路器监控问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答“SpringCloud怎么实现断路器监控”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
一、Hystrix仪表板简介
在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的
可用性和健壮性,它是一个重要指标.Hystrix仪表板是作
为断路器状态的一个组件,提供了数据监控和友好的图形化界面。
二,准备工作
本文的的来源于第一篇文章的栗子,在它的基础上进行改造。
三,开始改造service-hi
在pom的工程文件引入相应的依赖:
& lt; dependencies> ,,,,,,,& lt; dependency> ,,,,,,,,,,,& lt; groupId> org.springframework.cloud ,,,,,,,,,,,& lt; artifactId> spring-cloud-starter-netflix-eureka-client ,,,,,,,& lt;/dependency> ,,,,,,,& lt; dependency> ,,,,,,,,,,,& lt; groupId> org.springframework.boot ,,,,,,,,,,,& lt; artifactId> spring-boot-starter-web ,,,,,,,& lt;/dependency> ,,,,,,,& lt; dependency> ,,,,,,,,,,,& lt; groupId> org.springframework.boot ,,,,,,,,,,,& lt; artifactId> spring-boot-starter-actuator ,,,,,,,& lt;/dependency> ,,,,,,,& lt; dependency> ,,,,,,,,,,,& lt; groupId> org.springframework.cloud ,,,,,,,,,,,& lt; artifactId> spring-cloud-starter-netflix-hystrix ,,,,,,,& lt;/dependency> ,,,,,,,& lt; dependency> ,,,,,,,,,,,& lt; groupId> org.springframework.cloud ,,,,,,,,,,,& lt; artifactId> spring-cloud-starter-netflix-hystrix-dashboard ,,,,,,,& lt;/dependency> ,,,,,,, ,,,& lt;/dependencies>
其中,这三个依赖是必须的,缺一不可。
在程序的入口ServiceHiApplication类,加上@EnableHystrix注解开启断路器,这个是必须的,并且需要在程序中声明断路点
HystrixCommand;加上@EnableHystrixDashboard注解,开启HystrixDashboard
@SpringBootApplication @EnableEurekaClient @EnableDiscoveryClient @RestController @EnableHystrix @EnableHystrixDashboard @EnableCircuitBreaker public class  ServiceHiApplication { ,,,/* * ,,,,*,访问地址,http://localhost: 8762/致动器/hystrix.stream ,,,,*,@param 参数 ,,,*/,,,public static void main (String [], args), { ,,,,,,,SpringApplication.run (ServiceHiApplication.class的不同之处是,args ); ,,,} ,,,@ value (“$ {server.port}“) ,,,String 港口; ,,,@RequestMapping (“/hi") ,,,@HystrixCommand (=fallbackMethod “hiError") ,,,public String 回家(@RequestParam (=value “name",, defaultValue =,“forezp"), String 名称),{ ,,,,,,,return “hi “, +, name +,“,,小姐:am 得到端口:“,+,港口; ,,,} ,,,public String hiError (String 名称),{ ,,,,,,,return “嗨,“+名称+“,对不起,错误!“; ,,,} }
运行程序:依次开启eureka-server和service-hi。
四,Hystrix仪表板图形展示
打开http://localhost: 8762/致动器/Hystrix。流,可以看到一些具体的数据:
打开localhost: 8762/hystrix可以看见以下界面:
在界面依次输入:http://localhost: 8762/致动器/hystrix。2000年流,米亚,点确定。
在另一个窗口输入:http://localhost: 8762/嗨? name=forezp
重新刷新hystrix。null