springcloud  Hystrix Dashboard微服务监控简介

Hystrix监控

除了隔离依赖服务的调用以外,Hystrix还提供了近实时的监控,Hystrix会实时、累加地记录所有关于HystrixCommand的执行信息,包括每秒执行多少请求多少成功,多少失败等。Netflix通过hystrix-metrics-event-stream项目实现了对以上指标的监控。springcloud也对Hystrix dashboard的整合,对监控内容转化成可视化的界面

 

springcloud  Hystrix Dashboard微服务监控实战

1,新建微服务监控工程microservicecloud-consumer-hystrix-dashboard

2,pom文件引入微服务监控jar包

 

pom文件需要的jar

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>microservicecloud</artifactId>
        <groupId>com.atguigu.springcloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>microservicecloud-consumer-hystrix-dashboard</artifactId>


    <dependencies>
        <!-- 自己定义的api -->
        <dependency>
            <groupId>com.atguigu.springcloud</groupId>
            <artifactId>microservicecloud-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 修改后立即生效,热部署 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <!-- Ribbon相关 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <!-- feign相关 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>
        <!-- hystrix和 hystrix-dashboard相关 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
        </dependency>
    </dependencies>

</project>

3,修改启动类添加@EnableHystrixDashboard注解开启微服务监控

package com.atguigu.springcloud;

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

@SpringBootApplication
@EnableHystrixDashboard
public class DeptConsumer_DashBoard_App {
	public static void main(String[] args) {
		SpringApplication.run(DeptConsumer_DashBoard_App.class, args);
	}
}

4,编写yml文件设置内置tomcat端口

5,所有的provider微服务提供者(8001/8002/8003)都需要监控依赖配置

pom文件添加

 

6,启动相关的微服务

   6.1启动microservicecloud-consumer-hystrix-dashboard微服务监控

       微服务监控成功启动可以看到如下:http://localhost:9001/hystrix

   6.2启动3个eureka集群

   6.3启动microservicecloud-provider-dept-hystrix-8001

 

整除访问监控数据:http://localhost:8001/hystrix.stream

 

通过这样的方式估计你也看不明白,这是一堆json串解析也不方便,我们希望有更好的办法直观的视图显示

别急我们前面就提到过springcloud也对Hystrix dashboard的整合,对监控内容转化成可视化的界面,下面我们就看看怎么玩吧

 

 

 

如何查看监控指标?

 

刷新之后圈圈变大了,一线也升高了(调用的频次     绿色0升到大14)流量压力

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐