跳至主内容

调试 RabbitMQ Kubernetes Operator

本文档介绍了如何调试正在运行的 RabbitMQ Kubernetes Operator 实例。

获取 Kubernetes Operator Pod 的 CPU/内存使用情况信息

警告

以下步骤仅在调试特定部署中的 Operator 时才需要执行。

在生产系统上运行这些步骤之前请三思。

通过使用 pprof 工具,您可以公开 Kubernetes Operator Pod 的 CPU 和内存性能分析数据。性能分析(Profiling)是一种调试技术,通过公开软件在内存、CPU 和异步处理方面的消耗信息,来生成关于软件运行状况的数据。

例如,当您观察到某个 Operator Pod 的资源消耗过高时,可能需要执行此操作。要使用 pprof 工具,请按照以下步骤将其启用:

  1. 运行以下命令,为您想要获取调试信息的 Operator 启用 ENABLE_DEBUG_PPROF 变量。例如,对于 Cluster Operator,请运行:
kubectl -n rabbitmq-system set env deployment/rabbitmq-cluster-operator ENABLE_DEBUG_PPROF=True
# => deployment.apps/rabbitmq-cluster-operator env updated
  1. 使用 kubectl 执行 port-forward 操作,以便在您的本地机器上从 Operator Pod 的正确端口收集指标。对于 RabbitMQ Cluster Operator,默认端口是 9782;对于所有其他 Operator,端口是 8080。例如,要对 RabbitMQ Cluster Operator Pod 执行 port-forward 操作,请运行:
kubectl -n rabbitmq-system port-forward deployment/rabbitmq-cluster-operator 9782
# => Forwarding from 127.0.0.1:9782 -> 9782
# => Forwarding from [::1]:9782 -> 9782
  1. 现在,在另一个终端中,您可以使用 go tool pprof 来分析 Operator Pod。例如,要分析 Pod 中的内存分配情况,请运行:
go tool pprof "localhost:9782/debug/pprof/heap"
# => Fetching profile over HTTP from https://:9782/debug/pprof/heap
# => Saved profile in /home/pprof/pprof.manager.alloc_objects.alloc_space.inuse_objects.inuse_space.001.pb.gz

这将打开一个浏览器窗口,以可视化方式展示性能分析中的内存分配情况。有关如何使用 pprof 的更多信息,请参见此处

下表列出了 Operator 公开的性能分析配置(Profiles):

路径性能分析说明
/debug/pprof系统中所有可用性能分析配置的列表。
/debug/pprof/allocs所有过去内存分配的样本。
/debug/pprof/block导致在同步原语上阻塞的堆栈跟踪。
/debug/pprof/cmdline当前程序的命令行调用。
/debug/pprof/goroutine所有当前 Goroutine 的堆栈跟踪。
/debug/pprof/heap活跃对象内存分配的样本。您可以指定 gc GET 参数,在获取堆样本之前运行 GC。例如:/debug/pprof/heap?gc=1
/debug/pprof/mutex互斥锁竞争持有者的堆栈跟踪。
/debug/pprof/profileCPU 性能分析。您可以通过 seconds GET 参数指定持续时间。例如:/debug/pprof/profile?seconds=5
/debug/pprof/threadcreate导致创建新操作系统线程的堆栈跟踪。
/debug/pprof/trace当前程序执行的追踪。您可以通过 seconds GET 参数指定持续时间。例如:/debug/pprof/trace?seconds=5
© . This site is unofficial and not affiliated with VMware.