本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3
本文基于前两篇文章eureka-server、eureka-client、eureka-ribbon和eureka-feign的实现。
参考java
Hystrix Dashboard时Hystrix提供的一个能够查看hystrix监控数据的控制面板。Hystrix提供了近实时的数据监控,Hystrix会实时、累加的记录全部关于HystrixCommand的执行信息,包括每秒执行多少请求,多少成功和多少失败等。git
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency>
spring: application: name: hystrix-dashboard server: port: 8500 eureka: instance: hostname: localhost lease-renewal-interval-in-seconds: 5 lease-expiration-duration-in-seconds: 10 client: service-url: defaultZone: http://eureka1.server.com:8701/eureka/,http://eureka2.server.com:8702/eureka/,http://eureka3.server.com:8703/eureka/
package spring.cloud.demo.hystrixdashboard; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @EnableHystrixDashboard @EnableDiscoveryClient @SpringBootApplication public class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); } }
@EnableHystrixDashboard:启动Hystrix Dashboard断路器看板相关配置
打开浏览器,输入http://localhost:8500/hystrix显示结果以下:github
url输入框:表明要监控的服务消费者Single Hystrix App: https://hystrix-app:port/actuator/hystrix.stream:要监控路径url格式web
package spring.cloud.demo.eurekaribbon.config; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * @auther: maomao * @DateT: 2019-09-17 */ @Configuration public class HystrixConfig { @Bean public ServletRegistrationBean getServlet() { HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; } }
启动eureka-client和eureka-ribbon服务。而后在hystrix dashboard控制面板url框中输入:spring
点击Monitor Stream会显示:segmentfault
- Unable to connect to Command Metric Stream问题缘由:由于咱们开启监控的断路器流Hystrix Stream路径http://localhost:8901/hystrix.stream不是spring boot的默认路径,也不是hystrix的默认路径,全部要增长Hystrixconfig来制定断路器的指标流Servlet。
- 首次成功启动页面也有可能会显示loading,这表明尚未访问咱们要监控的服务,这是咱们能够屡次请求要访问的服务就能够看到指标数据
按照一样的方式我能够设置eureka-feign的配置来进行监看。浏览器
本文简单的搭建了Hystrix Dashborad数据监控平台。Hystrix如今已是中止开发,处于维护阶段,在Github上Hystrix已经说明,建议咱们使用Resilience4J。后续会更新关于Resilience4J的简单实用。app
gitHub地址分布式
<center><font color=red>《Srping Cloud 2.X小白教程》目录</font></center>spring-boot
转载请注明出处,