<五>spring-cloud Hoxton.SR2 hystrix Dashboard监控搭建使用

<五>spring-cloud Hoxton.SR2 hystrix Dashboard监控搭建使用


本地项目的基础环境

环境版本
jdk1.8.0_201
maven3.6.0
Spring-boot2.2.4.RELEASE
Spring-cloudHoxton.SR2

本次例子是基于上一次构建的badger-spring-cloud-openfeign-hystrix项目的基础上,使用的;

《<一>spring-cloud Hoxton.SR2版 服务注册与发现–eureka搭建以及集群搭建》

《<二>spring-cloud Hoxton.SR2 负载均衡ribbon搭建使用》

《<三>spring-cloud Hoxton.SR2 负载均衡openfeign搭建使用》

《<四>spring-cloud Hoxton.SR2 断路器hystrix搭建使用》

具体代码信息,可以查看《码云》

hystrix的断路器,还提供了实时监控的页面系统Hystrix-Dashboard,Hystrix会持续的记录所有通过Hystrix发起的请求执行信息(请求次数、成功、失败……);并转换成界面的形式展示;

1、项目搭建

1.1、新建项目badger-spring-cloud-hystrix-dashboard,pom文件如下, 引入hystrix和 hystrix-dashboard相关

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.badger</groupId>
    <artifactId>badger-spring-cloud-hystrix-dashboard</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>bbadger-spring-cloud-hystrix-dashboard</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
        <spring-cloud.version>Hoxton.SR2</spring-cloud.version>
    </properties>

    <dependencies>
        <!-- hystrix和 hystrix-dashboard相关 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

1.2、新建主启动类HystrixDashboardApplication,并且加上@EnableHystrixDashboard注解

/**
 * @EnableHystrixDashboard  开启断路器仪表盘 hystrix dashboard 
   http://localhost:8764/hystrix
 * @author liqi
 *
 */
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {

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

1.3、ymal配置文件,就只是配置了启动端口8764

server:
  port: 8764

1.4、启动项目

http://localhost:8764/hystrix

看到这个豪猪的页面,项目就搭建完成了,下面说明下页面上要表达的意思

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

  1. default cluster(查看默认的集群):http://turbine-hostname:port/turbine.stream
  2. custom cluster(查看指定的集群节点):http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
  3. Single Hystrix App(单个应用):http://hystrix-app:port/actuator/hystrix.stream

三个输入框

第一个:输入需要监控应用的地址

Delay:刷新的频率 默认是2秒(2000ms)

Title:应用的标题

1.5、被监控的应用,改造上一篇搭建的badger-spring-cloud-openfeign-hystrix应用;新增actuator监控的jar包

 <!-- actuator监控信息 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

yaml配置文件中,新增

management:
  endpoints:
    web:
      exposure:
        include: '*'

新增这个配置,是开放所有的actuator监控路径,springboot2.x之后,只暴露了info和health两个节点,并且actuator监控的路由,加了/actuator路由

部分actuator监控的配置类如下org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties

@ConfigurationProperties(prefix = "management.endpoints.web")
public class WebEndpointProperties {

	private final Exposure exposure = new Exposure();

	/**
	 * Base path for Web endpoints. Relative to server.servlet.context-path or
	 * management.server.servlet.context-path if management.server.port is configured.
	 */
	private String basePath = "/actuator";

	/**
	 * Mapping between endpoint IDs and the path that should expose them.
	 */
	private final Map<String, String> pathMapping = new LinkedHashMap<>();

	public Exposure getExposure() {
		return this.exposure;
	}

yaml全部配置如下

server:
  port: 7300
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
    prefer-ip-address: true
spring:
  application:
    name: badger-spring-cloud-openfeign-hystrix
feign:
  hystrix:
    enabled: true
management:
  endpoints:
    web:
      exposure:
        include: '*'

2、项目启动,演示测试

启动步骤如下:

  1. 启动eureka的服务,端口8761;
  2. 修改yaml的配置文件,启动端口为7000,启动服务的提供者badger-spring-cloud-api;
  3. 启动服务的消费者badger-spring-cloud-openfeign-hystrix,端口为7300;

调用openfeign的服务 http://localhost:7300/feign/demo

我的地址是-->172.16.2.50:7001

说明项目正常;

在Hystrix Dashboard的页面里,输入地址

http://localhost:7300/actuator/hystrix.stream

点击监监控的按钮,如图所示

点击结果

通过浏览器,不断刷新 http://localhost:7300/feign/demo 可以看到监控的页面,不断的在变化

	@Bean
	@ConditionalOnMissingBean
	public IRule ribbonRule(IClientConfig config) {
		if (this.propertiesFactory.isSet(IRule.class, name)) {
			return this.propertiesFactory.get(IRule.class, config, name);
		}
		ZoneAvoidanceRule rule = new ZoneAvoidanceRule();
		rule.initWithNiwsConfig(config);
		return rule;
	}

大家可以直接切换成轮询算法,再测试一次,切换的方式,就是注入一个IRule接口的实例,就可以了

我就不在演示了。

实心圆:请求的频率越高,流量越大,圆也越大;圆的颜色,也表示应用的健康程度,健康度从绿色、黄色、橙色、红色递减;

曲线:就一段时间里,请求的频次

其他的指标:上图中,红色框框住的部分,根据颜色来对应的,例如图中红框里的的数字37对应的颜色Success;表示成功的请求;

具体代码信息,可以查看《码云》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

葵花下的獾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值