Hystrix Dashboard监控面板

本文介绍如何使用Hystrix Dashboard实现微服务实时监控。包括引入依赖、配置启动类等步骤,最后演示如何监控服务状态。

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

Hystrix Dashboard监控面板

概述

本篇博文引入Hystrix Dashboard实现对微服务的实时监控及界面化监控。

实现步骤分析

引入相关依赖依赖

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

创建application.yml文件

spring:
  application:
    name: hystrix-dashboard
server:
  port: 9100

创建springcloud-hystrix-dashboard启动类

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

@EnableHystrixDashboard // 启动hystrix监控面板
@SpringBootApplication
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

此时,启动项目,并在浏览器里访问http://localhost:9100/hystrix/即可进入Hystrix Dashboard监控首页面,如下图所示:
这里写图片描述

监控首页面根据不同的架构模式提供了有一种监控方式:

  1. Cluster via Turbine (default cluster): http://turbine-hostname:port/turbine.stream(这是针对Turbine集群(默认集群))
  2. Cluster via Turbine (custom cluster): http://turbine-hostname:port/turbine.stream?cluster=clusterName
  3. Single Hystrix App: http://hystrix-app:port/hystrix.stream(单体应用模式)

以上仅实现了Hystrix Dashboard监控系统搭建,下面介绍如何实现对服务的监控

Hystrix Dashboard服务监控

Single Hystrix App单体应用模式

要实现服务的监控,需要修改被监控服务的配置及依赖,本例以springcloud-service-consumer-feign-hystrix这个工程为服务消费端介绍如何实现监控。

修改消费端pom依赖,引入Hystrix Dashboard依赖

需要增加以下依赖:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
启动熔断机制

在主启动类上增加@EnableCircuitBreaker
修改后的启动类如下:

@SpringBootApplication
@EnableFeignClients // 启动Feign
@EnableCircuitBreaker // 启动熔断机制
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

测试

分别启动springcloud-hystrix-dashboardspringcloud-service-consumer-feign-hystrix这两个工程,在浏览器里多次访问http://localhost:9000/consumer/request/info,并通过http://localhost:9100/hystrix/monitor?stream=http://localhost:9000/hystrix.stream即可查看监控的详细信息,如下图:
这里写图片描述

Cluster via Turbine (default cluster) | Cluster via Turbine (custom cluster)

后续补齐

源代码链接:
https://github.com/myNameIssls/springcloud-study/tree/master/springcloud-hystrix-dashboard

参考链接:
http://cloud.spring.io/spring-cloud-static/Finchley.SR1/multi/multi__circuit_breaker_hystrix_dashboard.html
http://cloud.spring.io/spring-cloud-static/Finchley.SR1/multi/multi__hystrix_timeouts_and_ribbon_clients.html
https://blog.youkuaiyun.com/yejingtao703/article/details/77683102
https://www.cnblogs.com/chenweida/p/9025589.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值