Spring Cloud--Hystrix配置Dashboard,Turbine集群监控

前言

Github:https://github.com/yihonglei/thinking-in-springcloud

Eureka注册中心:eureka-server

服务提供者(订单服务):eureka-provider-order

Feign-api(服务接口抽象):eureka-feign-api

Feign客户端消费(含hystrix和dashboard):eureka-consumer-feign-hystrix-dashboard

仪表盘:eureka-hystrix-dashboard

服务熔断:eureka-consumer-hystrix

集群监控:eureka-hystrix-turbine(新增工程)

在使用turbine集群之前,需要先搭建好hystrix-dashboard单个服务监控仪表盘。

参考:https://blog.csdn.net/yhl_jxy/article/details/95329627

一 turbine实例

1、项目结构

2、pom.xml依赖

<!-- 监控 -->
 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-actuator</artifactId>
 </dependency>
<!-- turbine -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>

3、application.yml配置

server:
  port: 9002
spring:
  application:
    name: eureka-hystrix-turbine
eureka:
  client:
    service-url:
      defaultZone: http://localhost:9000/eureka/
  instance:
    prefer-ip-address: true
turbine:
  aggregator:
    clusterConfig: default
  appConfig: eureka-consumer-feign-hystrix-dashboard,eureka-consumer-hystrix
  cluster-name-expression: "'default'"

turbine.appConfig配置微服务应用名称,对应每个微服务的spring.application.name的名字。

4、EurekaTurbineApplication启动类

package com.lanhuigu.turbine;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

/**
 * @auther: yihonglei
 * @date: 2019-07-11 16:59
 */
@SpringBootApplication
@EnableTurbine
public class EurekaTurbineApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaTurbineApplication.class);
    }
}

@EnableTurbine开启turbine。

服务启动后直接访问http://localhost:9002/turbine.stream地址,效果如下:

这里是json显示,下面会将其配置到dashboard仪表盘里面。

 二 服务启动

1、启动注册中心

eureka-server工程。

2、启动服务提供者

eureka-provider-order工程。

3、启动hystrix相关工程

eureka-consumer-feign-hystrix-dashboard工程,eureka-consumer-hystrix工程。

4、启动仪表盘

如果没有启动eureka-hystrix-turbine工程,需要启动。

然后启动eureka-hystrix-dashboard工程。

三 turbine配置和服务访问

1、注册中心(eureka-server)

http://localhost:9000/

2、访问仪表盘(eureka-hystrix-dashboard)

http://localhost:9001/hystrix/

3、turbine集群监控配置

http://localhost:9001/hystrix/(eureka-hystrix-dashboard)仪表盘页面配置

配置turbine集群监控访问地址http://localhost:9002/turbine.stream,并把Delay和Title配置。

配置完成后,点击Monitor Stream按钮进入集群监控页面。

一开始看到的页面是一个一直显示Loading...的页面,因为没有任何服务发生访问,

turbine拿不到服务信息,不知道显示啥,所以一直就是Loading...

如果你在进入这个页面之前,访问过trubine要监控的服务,就会显示服务仪表盘。

 通过http://localhost:8009/user/queryUserInfo访问服务(

eureka-consumer-feign-hystrix-dashboard),然后看到访问接口仪表盘如下。

这里只是其中一个服务,我们通过http://localhost:8005/user/queryOrderInfo访问eureka-consumer-hystrix服务,

可以看到另外一个服务仪表盘。

这就是turbine集群监控的意义,将每个工程的监控聚合到turbine里面,将要监控的服务仪表盘统一在一个界面显示,

统一分析,统一管理。

发布了502 篇原创文章 · 获赞 358 · 访问量 118万+

猜你喜欢

转载自blog.csdn.net/yhl_jxy/article/details/95635466