SpringCloud教程第9篇:断路监控面板(Hystrix Dashboard)(Finchley版本)

Hystrix Dashboard

Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。

1、新建一个工程hystrix-dashboard,修改 pom 文件,添加相关依赖。pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.bingo</groupId>
    <artifactId>hystrix-dashboard</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>hystrix-dashboard</name>
    <description>熔断监控面板</description>

    <parent>
        <groupId>com.bingo</groupId>
        <artifactId>cloud-example</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
    </dependencies>

</project>

2、在启动类中添加注解 @EnableHystrixDashboard 开启熔断监控支持。

package com.bingo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@EnableDiscoveryClient
@EnableHystrixDashboard  //开启熔断监控支持
@SpringBootApplication
public class HystrixDashboardApplication {

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

}

3、修改配置文件,配置启动端口和应用名称。application.yml

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
server:
  port: 8766
spring:
  application:
    name: hystrix-dashboard

4、修改service-ribbon服务,配置监控路径

/**
     * 此配置是为了服务监控而配置,与服务容错本身无关,
     * ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",
     * 只要在自己的项目里配置上下面的servlet就可以了
     * @return
     */
    @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;
    }

注意启动类要添加@EnableHystrix ,先后启动 eureka-server、 service-ribbon、hystrix-dashboard 服务。

访问:http://localhost:8766/hystrix/

此时没有任何具体的监控信息,需要输入要监控的消费者地址及监控信息的轮询时间和标题。

Hystrix Dashboard 共支持三种不同的监控方式:

单体Hystrix 消费者:通过URL http://hystrix-app:port/hystrix.stream 开启,实现对具体某个服务实例的监控。

默认集群监控:通过URL http://turbine-hostname:port/turbine.stream 开启,实现对默认集群的监控。

自定集群监控:通过URL http://turbine-hostname:port/turbine.stream?cluster=[clusterName] 开启,实现对clusterName集群的监控。

我们这里现在是对单体 Hystrix 消费者的监控,后面整合 Turbine 集群的时候再说明后两种的监控方式。

5、确认服务可以正常访问之后,在监控地址内输入http://localhost:8764/hystrix.stream,然后点击 Monitor Stream 开始监控。

 

刚进去,页面先显示 loading... 信息, 多次访问 http://localhost:8764/feign?name=zhangsan 之后,统计图表信息如下图所示。

参考资料:

https://blog.csdn.net/forezp/article/details/81041113 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值