Spring Clold: 第八章 HystrixDashboard监控

1.除了隔离依赖服务的调用以外,Hystrix还提供 了准实时的调用监控(Hystrix dashboard), Hystrix会持续地记录所有通过。Hystrix发起的请求的执行信息,并以统计报表和图形的形式展示给用户,包括每秒执行多少请求多少成功,多少失败等。
Netfix通过hystrix-metrics- event-stream项目实现了对以上指标的监控。Spring Cloud也提供了Hystrix Dashboard的整合,对监控内容转化成可视化界面。

2.新建一个hystrixDashboard(服务监控)项目其结构如下
在这里插入图片描述
Pox:(SpringBoot2一定要用2.2.2RELAEASE,如果版本太高Hystrix Dashboard
会一直显示loading)

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
    <!-- 默认使用的版本是 2.2.2.RELEASE-->
    <version>2.2.2.RELEASE</version>
</dependency>

Application加上@EnableHystrixDashboard

@EnableHystrixDashboard
@SpringBootApplication
public class HystrixApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixApplication.class, args);
    }

}

Yml

server:
  port: 9001

启动改项目输入网址访问http://localhost:9001/hystrix 出现如下画面则成功
在这里插入图片描述
3.被监控项目xml加上(dashboard一定要用2.2.2.RELELASE,否则页面加载不出来)

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    <version>2.0.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
    <!-- 默认使用的版本是 2.2.2.RELEASE-->
    <version>2.2.2.RELEASE</version>
</dependency>

新建一个HystrixMetricsStreamConfig

@Configuration
public class HystrixMetricsStreamConfig {

    @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;
    }
}

Yml开启端口暴露

management:
  endpoints:
    web:
      exposure:
        include: "*"
  1. 启动Eureka和相关服务,访问http://localhost:被监控项目端口号/actuator/hystrix.stream出现则成功
    在这里插入图片描述
  2. 在9001的监控界面输入要监控的微服务(2004代表被监控的端口号)
    在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
(git地址git@gitee.com:zhu_can_admin/springcloud.git)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值