hystrixDashboard(服务监控)

1、新建项目

microservicecloud-consumer-hystrix-dashboard

2、yml文件

server:
  port: 9001

3、在pom.xml文件增加如下内容

    <dependencies>
        <!-- 自己定义的api -->
        <dependency>
            <groupId>com.yufeng.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>

4、主启动类添加EnableHystrixDashboard

@ EnableHystrixDashboard开启仪表盘监控注解

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

5、微服务提供者添加监控jar

例如:微服务提供者 microservicecloud-provider-dept-8001/8002/8003

pom.xml文件添加以下jar包,才能被dashboard监控

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

6、测试

(1)启动3个 eureka 服务;

(2)启动新建的监控服务:microservicecloud-consumer-hystrix-dashboard

(3)浏览器中访问:http://localhost:9001/hystrix,若显示如下图所示,则表示微服务监控服务正常启动;


(3)启动被监控的带Hystrix的微服务: microservicecloud-provider-dept-hystrix-8001

<1> 在浏览器中打开:http://localhost:8001/hystrix.stream (即:http://{hystrix-app}:{port}/hystrix.stream)

<2> 在9001的监控界面输入要监控的微服务(http://localhost:8001/hystrix.stream),如下所示:

显示以下监控内容:

(a)Deplay 该参数用来控制服务器上轮询监控信息的延迟时间,默认是2000毫秒,可以通过配置该属性来降低客户端的网络和cpu消耗。

(b)Title该参数对应了头部标题Hystrix Stream之后的内容,默认会使用哦具体监控实例的URL,可疑通过配置该信息来展示更合适的标题。

<4> 在浏览器中输入:http://localhost:8001/dept/get/1,并多次刷新,显示如下:

实心圆:共有两种含义。它通过颜色的变化代表了实例的健康程度,它的健康程度从 绿色 > 黄色 > 橙色 > 红色 递减;

该实心圆除了颜色的变化之外,它的大小也会根据实例的请求流量发生变化,流量越大实心圆就越大,所以通过该实心圆的展示,就可以在大量实例中快速的发现故障实例和高压力实例

<5> 说明

原文地址:https://www.cnblogs.com/yufeng218/p/11489175.html