当前位置: 首页 > article >正文

【ETCD】【实操篇(十八)】ETCD监控实战:提升系统健康与集群调试效率

在现代分布式系统中,监控是确保服务高可用性和性能稳定的重要组成部分。对于 ETCD 集群而言,监控不仅可以帮助我们检测系统健康,还能在出现故障时进行快速调试。ETCD 通过多种监控端点提供了详尽的性能指标和调试信息,本篇文章将介绍如何高效地利用 ETCD 提供的监控数据来提升集群的稳定性和可靠性。
在这里插入图片描述

ETCD监控概述

每个 ETCD 服务器都通过其客户端端口暴露本地监控信息,数据包括了集群状态、性能指标、日志级别调试信息等,便于进行健康检查与故障排查。ETCD 提供了多个专门的调试和监控端点,支持系统健康检查、性能分析、故障诊断等多种操作。

1. 调试端点

在 ETCD 配置中,如果启用 --log-level=debug,服务器将通过 /debug 路径暴露调试信息。这些信息对于分析 ETCD 的内部工作状态和进行故障排查非常有帮助。请注意,启用调试模式会增加日志量并可能导致性能下降,因此建议在故障排查时使用。

/debug/pprof 端点

/debug/pprof 是 Go 运行时的标准性能分析端点,可以帮助我们分析 CPU、堆内存、互斥锁和 goroutine 的使用情况。例如,可以使用 go tool pprof 获取 ETCD CPU 使用的详细情况:

$ go tool pprof http://localhost:2379/debug/pprof/profile

此命令将下载 CPU 使用的性能分析数据,帮助我们识别系统性能瓶颈。以下是一个示例输出,列出了 ETCD 中 CPU 占用最多的函数:

C:\Users\admin>go tool pprof http://localhost:2379/debug/pprof/profile
Fetching profile over HTTP from http://localhost:2379/debug/pprof/profile
Saved profile in C:\Users\admin\pprof\pprof.etcd.exe.samples.cpu.001.pb.gz
File: etcd.exe
Build ID: D:\data\etcd.exe2024-12-19 11:11:08.2450555 +0800 CST
Type: cpu
Time: Dec 26, 2024 at 10:05am (CST)
Duration: 30.01s, Total samples = 250ms ( 0.83%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 160ms, 64.00% of 250ms total
Showing top 10 nodes out of 92
      flat  flat%   sum%        cum   cum%
      40ms 16.00% 16.00%       40ms 16.00%  runtime.stdcall1
      30ms 12.00% 28.00%       30ms 12.00%  runtime.cgocall
      20ms  8.00% 36.00%       50ms 20.00%  runtime.selectgo
      10ms  4.00% 40.00%       10ms  4.00%  bufio.(*Reader).Read
      10ms  4.00% 44.00%       10ms  4.00%  runtime.checkTimers
      10ms  4.00% 48.00%       10ms  4.00%  runtime.execute
      10ms  4.00% 52.00%       70ms 28.00%  runtime.findRunnable
      10ms  4.00% 56.00%       10ms  4.00%  runtime.gopark
      10ms  4.00% 60.00%       10ms  4.00%  runtime.growWork_fast64
      10ms  4.00% 64.00%       10ms  4.00%  runtime.mapdelete
    ...
/debug/requests 端点

此端点提供 gRPC 调用的跟踪信息和性能统计,通过浏览器可以查看每个请求的详细执行情况。例如,以下是一个对键 abcRange 请求的日志:

/debug/requests
grpc.Recv.etcdserverpb.Auth	[0 active]	[≥0s]	[≥0.05s]	[≥0.1s]	[≥0.2s]	[≥0.5s]	[≥1s]	[≥10s]	[≥100s]	[errors]	[minute]	[hour]	[total]
grpc.Recv.etcdserverpb.Cluster	[0 active]	[≥0s]	[≥0.05s]	[≥0.1s]	[≥0.2s]	[≥0.5s]	[≥1s]	[≥10s]	[≥100s]	[errors]	[minute]	[hour]	[total]
grpc.Recv.etcdserverpb.KV	[0 active]	[≥0s]	[≥0.05s]	[≥0.1s]	[≥0.2s]	[≥0.5s]	[≥1s]	[≥10s]	[≥100s]	[errors]	[minute]	[hour]	[total]
grpc.Recv.etcdserverpb.Maintenance	[0 active]	[≥0s]	[≥0.05s]	[≥0.1s]	[≥0.2s]	[≥0.5s]	[≥1s]	[≥10s]	[≥100s]	[errors]	[minute]	[hour]	[total]
Family: grpc.Recv.etcdserverpb.KV
[Normal/Summary] [Normal/Expanded] [Traced/Summary] [Traced/Expanded]
Completed Requests
When	Elapsed (s)
2024/12/26 09:38:27.694690	0.010501	/etcdserverpb.KV/Compact
09:38:27.694690	 .      	... RPC: from 127.0.0.1:57267 deadline:4.998501s
...

2. 性能指标端点

ETCD 还通过 /metrics 端点暴露了丰富的指标,帮助我们监控集群的各项性能数据。这些指标包括磁盘延迟、请求延迟、流量等,可以通过 curl 命令获取:

http://localhost:2379/metrics

这会返回 ETCD 的相关性能数据,例如:

# HELP etcd_cluster_version Which version is running. 1 for 'cluster_version' label with current cluster version
# TYPE etcd_cluster_version gauge
etcd_cluster_version{cluster_version="3.5"} 1
# HELP etcd_debugging_auth_revision The current revision of auth store.
# TYPE etcd_debugging_auth_revision gauge
etcd_debugging_auth_revision 9
# HELP etcd_debugging_disk_backend_commit_rebalance_duration_seconds The latency distributions of commit.rebalance called by bboltdb backend.
# TYPE etcd_debugging_disk_backend_commit_rebalance_duration_seconds histogram
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.001"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.002"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.004"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.008"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.016"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.032"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.064"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.128"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.256"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="0.512"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="1.024"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="2.048"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="4.096"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="8.192"} 25
etcd_debugging_disk_backend_commit_rebalance_duration_seconds_bucket{le="+Inf"} 25
...

3. 健康检查端点

从 ETCD v3.3.0 开始,ETCD 增加了 /health 端点,能够提供更加详细的健康检查信息。如果集群配置了互斥的客户端 TLS 认证,或者使用负载均衡器进行监控时,可以通过该端点进行健康状态的快速访问。

/livez 和 /readyz 端点

在 ETCD v3.5.12 版本中,新增了 /livez/readyz 两个健康检查端点:

  • /livez:检查 ETCD 进程是否存活。
  • /readyz:检查 ETCD 是否准备好处理流量。

例如,执行以下命令可以获取详细的健康检查结果:

curl -k http://localhost:2379/readyz?verbose

返回结果可能如下所示,表示 ETCD 的各项健康检查均正常:

[+]data_corruption ok
[+]serializable_read ok
[+]linearizable_read ok
ok

如果需要排除某些检查,可以通过 exclude 参数来过滤,例如:

curl -k http://localhost:2379/readyz?exclude=data_corruption

4. Prometheus 集成

Prometheus 是一个流行的开源监控工具,可以轻松地收集和存储 ETCD 的监控数据。通过 Prometheus,我们可以在一个统一的平台上进行 ETCD 性能指标的可视化,帮助我们更好地理解集群的状态。

安装 Prometheus

首先,下载并安装 Prometheus,下载及安装教程可以参考
【prometheus】【实战篇(一)】使用二进制方式安装prometheus以及使用systemd管理,文末附一键安装脚本

配置 Prometheus

创建 Prometheus 配置文件,指定 ETCD 集群的监控端点:

global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
  - job_name: node
    static_configs:
      - targets: ['localhost:9100']
  - job_name: etcd
    static_configs:
      - targets: ['192.168.188.108:2379','192.168.188.108:2384','192.168.188.108:2383']


重启Prometheus

如果是通过文章所说的方式安装的prometheus,那么则可以通过如下方式来进行重启:

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart prometheus
[root@localhost ~]# systemctl status prometheus
● prometheus.service - Prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-12-26 03:28:36 UTC; 8s ago

在这里插入图片描述

通过grafana的来查看监控指标

从网址https://grafana.com/grafana/dashboards/22236-etcd/下载对应的模块,然后使用导入
在这里插入图片描述
点击load
在这里插入图片描述
点击import,
最后查看对应的操作面板
在这里插入图片描述

总结

通过本文介绍的 ETCD 调试端点、性能指标和健康检查功能,管理员可以实时了解 ETCD 集群的运行状况,提前发现潜在的性能瓶颈或故障。在生产环境中,结合 Prometheus 进行数据抓取与监控,将大大提升 ETCD 集群的可观察性和稳定性。


http://www.kler.cn/a/454646.html

相关文章:

  • platform_msi使用
  • 【Git】—— 使用git操作远程仓库(gitee)
  • httpclient GET 和POST 请求
  • Qt存储大整数到`JsonValue`
  • 赋能开发者 | 麒麟信安受邀参加2024开放原子开发者大会,以技术为引领,以人才创发展
  • 解读DeepseekV3
  • Go+chromedp实现Web UI自动化测试
  • uniapp 文本转语音
  • 挑战一个月基本掌握C++(第十二天)了解命名空间,模板,预处理器
  • 前端Python应用指南(五)用FastAPI快速构建高性能API
  • 同步异步日志系统:设计模式
  • ubuntu 账号从文本中的1000,改成0,后五笔输入法等中文输入法不可用,如何改回来
  • 【Ubuntu 20.4安装截图软件 flameshot 】
  • 全面Kafka监控方案:从配置到指标
  • 【自由能系列(初级),论文解读】神经网络中,熵代表系统的不确定性,自由能则引导系统向更低能量的状态演化,而动力学则描述了系统状态随时间的变化。
  • flask后端开发(11):User模型创建+注册页面模板渲染
  • 使用Python实现自动化文档生成工具:提升文档编写效率的利器
  • STM32F103RCT6学习之一:基本开发流程
  • FileLink为企业打造了一站式的跨网安全文件共享解决方案
  • Docker使用——国内Docker的安装办法