SpringCloud(三):监控中心 hystrix turbine

本文介绍如何使用Hystrix-Dashboard和Turbine实现SpringCloud服务的监控与数据聚合,通过配置实现服务健康状态的实时监控,适用于复杂分布式系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SpringCloud(三):监控中心 hystrix turbine

1.介绍
Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。但是只使用Hystrix Dashboard的话, 你只能看到单个应用内的服务信息, 这明显不够. 我们需要一个工具能让我们汇总系统内多个服务的数据并显示到Hystrix Dashboard上, 这个工具就是Turbine.

在基础服务工程里面创建一个模块用来创建一个监控中心
首先在pom.xml maven引入依赖

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    </dependency>
  </dependencies>

接着创建一个启动程序
@SpringBootApplication
@Controller
@EnableHystrixDashboard
public class HystrixApplication {
@RequestMapping("/")
public String home() {
return “forward:/hystrix”;
}

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

}
这里使用了注解 @EnableHystrixDashboard启动断路器仪表盘的功能

然后在应用的配置文件application.yml中增加如下配置
server:
port: 7979

endpoints:
restart:
enabled: true
shutdown:
enabled: true

logging:
level:
ROOT: INFO
org.springframework.web: DEBUG
启动这个项目 访问 http://localhost:7979/
在这里插入图片描述
输入这个服务的地址 http://localhost:8091/hystrix.stream
在这里插入图片描述

Turbine
在复杂的分布式系统中,相同服务的节点经常需要部署上百甚至上千个,很多时候,运维人员希望能够把相同服务的节点状态以一个整体集群的形式展现出来,这样可以更好的把握整个系统的状态。 为此,Netflix提供了一个开源项目(Turbine)来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。

pom.xml 中引入配置文件

  <dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-turbine</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-netflix-turbine</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>
</dependencies>

启动程序

@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
@EnableZipkinServer
public class ZipkinServerApplication {

public static void main(String[] args) throws Exception {
	new SpringApplicationBuilder(ZipkinServerApplication.class).web(true).run(args);
}

}
这个程序与上面的监控中心的启动程序类似 只多了2个注解 一个使用了eurekaz的服务发现功能 和使用一个turbine聚合监控的功能

在配置文件中配置 application.yml
server:
port: 8989
management:
port: 8991
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
non-secure-port: ${PORT:8989}
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/

turbine:
appConfig: catologapi,catologweb,catologwap
aggregator:
clusterConfig: default
clusterNameExpression: new String(“default”)

bootstrap.yml配置文件

spring:
application:
name: turbine

cloud:
config:
uri: http://localhost:8888

rabbitmq:
addresses: amqp://47.98.133.78:5672
username: guest
password: guest

启动程序启动成功访问页面
在这里插入图片描述

查看下配置中心
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值