Hystrix Dashboard(仪表盘)就是以一种有效的方式显示每个断路器的健康状况,通过仪表盘我们可以看到Hystrix的各项指标信息,以便于快速发现系统中存在的问题进而解决它。
Hystrix Dashboard有两种使用策略,一种是对单体应用的监控,另一种是整合Turbine,对集群进行监控。我们分别来进行介绍。
一.单体应用的监控
思路:应该是在需要监控的微服务上嵌入Hystrix仪表盘,但是作为微服务体系,我们没有必要为每一个微服务都嵌入Hystrix Dashboard。合适的做法是,我们需要专门创建一个工程来实现Hystrix Dashboard。
新建一个项目:ms-hystrix-dashboard
回顾一下之前使用Hystrix Dashboard实现单体应用监控图形化展示的步骤:
1、创建一个Spring Boot工程,引入spring-cloud、hystrix、hystrix-dashboard以及actuator的依赖。
2、在启动类中,添加“@EnableHystrixDashboard”注解,以开启仪表盘功能。
3、在resource文件夹下创建配置application.yml的基本配置项(应用名和应用端口)
4、访问“http://localhost:2001/hystrix”,可以看到Dashboard主页面,输入要监控工程的hystrix.stream监控地址即可看到监控页面。
1.pom文件:
<!-- hystrix 插件 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- dashboard -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<!-- actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.resources文件:
server:
port: 8006
spring:
application:
name: ms-hystrix-dashboard
#设置查看指标
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: "*"
exclude: "-"
3.启动类:
package com.ljf.weifuwu.springcloud.dashboard;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
/**
* Hello world!
*
*/
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApp
{
public static void main( String[] args )
{
SpringApplication.run(HystrixDashboardApp.class, args);
System.out.println( "Hello World!" );
}
}
4.启动服务:ms-eureka-center(8761)、ms-eureka-provider(9701)、ms-hystrix-consumer(8005)、ms-hystrix-dashboard(8006)
5.访问页面:


不停刷新:http://localhost:8005//hystrix-consumer/1 这个请求,可以看到下面两个页面不停的变化




本文详细介绍如何使用HystrixDashboard监控微服务健康状态,包括单体应用和集群监控策略。通过创建独立的监控工程,引入必要的依赖,配置监控参数,启动服务,最终实现实时监控并展示Hystrix各项指标。
1098

被折叠的 条评论
为什么被折叠?



