Hystrix Dashboard监控平台搭建(六)

Hystrix提供了准时的调用监控(Hystrix Dashboard),会持续地记录所有通过Hystrix发起的请求的执行信息,并以统计表和图形的形式展示给用户。

简单服务监控模块的搭建

1.创建springcloud-hystrix-dashboard-9001模块

2. 配置pom.xml

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.dsx</groupId>
    <artifactId>springcloud-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../springcloud-parent/pom.xml</relativePath>
  </parent>
  <artifactId>springcloud-hystrix-dashboard-9001</artifactId>
   <dependencies>
        <dependency>
            <groupId>com.dsx</groupId>
            <artifactId>springcloud-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <!--导入 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>
         <!--springboot web启动器-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
   </dependencies>
</project>

3.配置 application.yml

server:
  port: 9001

4. 创建启动类

    添加 @EnableHystrixDashboard 注解开启服务监控
package com.dsx;

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

@SpringBootApplication
@EnableHystrixDashboard //开启服务监控
public class HystrixDashboard_9001 {
	public static void main(String[] args) {
		SpringApplication.run(HystrixDashboard_9001.class, args);
	}
}

5. 搭建完成,启动后看到如下页面

6. 为要被监控的服务添加配置

     6.1  在需要监控的服务 pom.xml 中的 dependencies 节点中新增 spring-boot-starter-actuator 监控依赖, 以开启监控相关的端点,并确保已经引入断路器的依赖 spring-cloud-starter-netflix-hystrix

  6.2 在需要监控的服务 application.yml 配制中添加暴露端点

#在被监控服务上添加暴露端点
management:
  endpoints:
    web:
      exposure:
        include: hystrix.stream

或者在需要监控的服务的启动类中注入Bean,达到监控的目的。选择你喜欢的一种方式实现即可。

@Bean
	public ServletRegistrationBean hystrixMetricsStreamServlet() {
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
		registrationBean.addUrlMappings("/actuator/hystrix.stream");
		return registrationBean;
	}

7. 启动服务类,访问其中的一个接口。再次访问http://localhost:9001/hystrix,并按照上图中的要求填写页面信息进行访问

访问后看到如下页面

实心圆:共有两种含义。
它通过 颜色的变化代表了实例的健康程度 它的健康度从绿色 < 黄色 < 橙色 < 红色递减。 该实心圆除了颜色的变化之外,它的大小也会根据实例的请求流量发生变化, 流量越大该实心圆就越 大 。所以通过该实心圆的展示,就可以在大量的实例中快速的发现 故障实例和高压力实例
 
曲线:用来记录 2 分钟内流量的相对变化,可以通过它来观察到流量的上升和下降趋势。
 

至此,简单的监控平台就搭建完成了。如有不同意见,欢迎留言指正,望不吝赐教!!! 

发布了132 篇原创文章 · 获赞 1 · 访问量 7275

猜你喜欢

转载自blog.csdn.net/duan196_118/article/details/104358912