在高并发环境下, 服务器负担很重. 在服务器崩掉前及时做出调整很有必要, 为了能实时观察到服务器的压力和访问的具体情况, SpringCloud下的Hystrix提供了Dashboard流监控技术, 这里只介绍如何快速简单使用它的步骤
一般的流程应该像上图所示, 以下为了方便简洁, 将省去客户端 , 只有一个Eureka、一个服务端、一个监控者dashboard
监控者dashboard
建立一个新的组件作为dashboard来监控服务, 需要以下两个关键依赖:
<!--Hystrix-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<!--Hystrix-Dashboard-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
老规矩, 导完依赖, 就马上在主启动类贴标签开启功能:
改下端口, 我改成6001
服务端
关键依赖:
<!--让这个服务能够被监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
接着在主启动类里加上这段"死的"代码(固定写法,不需改动)
@Bean
public ServletRegistrationBean hystrixMetricsStreamServlet(){
ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
registrationBean.addUrlMappings("/actuator/hystrix.stream");
return registrationBean;
}
开始测试
依次把Eureka、服务端、dashboard监控者跑起来
先访问Eureka, 观察到服务正常注册了进来:
一步步往下,接下来看看充当监控者的dashboard是否OK ,由于刚才设置的端口号是6001, 这里访问http://localhost:6001/hystrix
出现这只…豪猪?! 就说明它OK!
再把服务端的端口号作为url地址(即http://localhost:8001), 后面再加上上文那段固定代码参数中的url后缀(即/actuator/hystrix.stream), 加上这股"流"之后最终的url地址(即http://localhost:8001/actuator/hystrix.stream)写到这里, 准备开始监控
点击Monitor Stream(监控流) 开始监控:
流监控图说明
实心圆: 颜色代表健康程度, 从绿色,黄色,橙色,红色递减, 大小代表流量, 越大则单位时间内访问次数越多
其他参数: