1.简单介绍
服务监控 hystrixDashboard
除了隔离依赖服务的调用以外,Hystrix还提供了准实时的调用监控(Hystrix Dashboard),Hystrix会
持续地记录所有通过Hystrix发起的请求的执行信息,并以统计报表和图形的形式展示给用户,包括每秒
执行多少请求,多少成功,多少失败等等。
Netflix通过hystrix-metrics-event-stream项目实现了对以上指标的监控,SpringCloud也提供了Hystrix
Dashboard的整合,对监控内容转化成可视化界面!
2.相关配置
新建工程springcloud-consumer-hystrix-dashboard-9001
Pom.xml
复制之前80项目的pom文件,新增以下依赖!
-
<dependency>
-
<groupId>org.springframework.cloud</groupId>
-
<artifactId>spring-cloud-starter-hystrix</artifactId>
-
<version>1.4.7.RELEASE</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework.cloud</groupId>
-
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
-
<version>1.4.7.RELEASE</version>
-
</dependency>
将端口号改为9001
修改主启动类:
-
package com.csh.springcloud;
-
import org.springframework.boot.SpringApplication;
-
import org.springframework.boot.autoconfigure.SpringBootApplication;
-
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
-
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
-
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
-
import org.springframework.cloud.openfeign.EnableFeignClients;
-
import org.springframework.context.annotation.ComponentScan;
-
@SpringBootApplication
-
@EnableHystrixDashboard//新注解,开启功能
-
public class Springcloudconsumer80feigndashboard {
-
public static void main(String[] args) {
-
SpringApplication.run(Springcloudconsumer80feigndashboard.class,args);
-
}
-
}
然后在provider中pom.xml文件中添加:
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-actuator</artifactId>
-
</dependency>
在 springcloud-provider-dept-hystrix-8001 启动类中增加一个bean:
-
@Bean
-
public ServletRegistrationBean hy()
-
{
-
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
-
servletRegistrationBean.addUrlMappings(“/actuator/hystrix.stream”);
-
return servletRegistrationBean;
-
}
3.结果
Delay : 该参数用来控制服务器上轮询监控信息的延迟时间,默认为2000毫秒,可以通过配置
该属性来降低客户端的网络和CPU消耗
Title : 该参数对应了头部标题HystrixStream之后的内容,默认会使用具体监控实例URL,可
以通过配置该信息来展示更合适的标题。
一圈
实心圆:公有两种含义,他通过颜色的变化代表了实例的健康程度
它的健康程度从绿色<黄色<橙色<红色 递减
该实心圆除了颜色的变化之外,它的大小也会根据实例的请求流量发生变化,流量越
大,该实心圆就越大,所以通过该实心圆的展示,就可以在大量的实例中快速发现故障
实例和高压力实例。