hystrixDashboard(服务监控)
注明:此项目为本人学习尚硅谷老师的教学视频然后整理核心的配置文件,所有的项目均在以下地址下载。
https://github.com/xwbGithub/microservicecloud下载
本项目请参考microservicecloud-consumer-hystrix-dashboard项目
核心文件介绍
1、新建项目
microservicecloud-consumer-hystrix-dashboard
pom文件的修改
<!-- hystrix和 hystrix-dashboard相关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
yml文件
server:
port: 9001
主启动类添加EnableHystrixDashboard
@ EnableHystrixDashboard开启仪表盘监控注解
@SpringBootApplication
@EnableHystrixDashboard
public class DeptConsumer_DashBoard_App {
public static void main(String[] args) {
SpringApplication.run(DeptConsumer_DashBoard_App.class, args);
}
}
微服务提供者添加监控jar
例如微服务提供者microservicecloud-provider-dept-8001/8002/8003
添加以下jar包,才能被dashboard监控
<!-- actuator监控信息完善 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
测试:
1、启动dashboard监控微服务http://localhost:9001/hystrix
2、然后启动3个集群服务,启动microservicecloud-provider-dept-hystrix-8001
输入访问地址:http://localhost:8001/hystrix.stream
在9001的监控界面输入要监控的微服务(http://localhost:8001/hystrix.stream)
会看到以下监控内容
(1)Deplay 该参数用来控制服务器上轮询监控信息的延迟时间,默认是2000毫秒,可以通过配置该属性来降低客户端的网络和cpu消耗。
(2)Title该参数对应了头部标题Hystrix Stream之后的内容,默认会使用哦具体监控实例的URL,可疑通过配置该信息来展示更合适的标题。