如何在 Prometheus 上的 Kubernetes 集群上为 pod 运行 查找关于 CPU/MEM 的指标

How to find metrics about CPU/MEM for the pod running on a Kubernetes cluster on Prometheus

我通过 Terraform 的 Helm 安装了 Prometheus,它被配置为连接到我的 Kubernetes 集群。我打开我的 Prometheus,但我不确定从列表中选择哪个指标才能查看 运行 pods/jobs 的 CPU/MEM。 下面是所有的pods运行命令(test1是kubenamespace):

kubectl -n test1 get pods

podsrunning

当我在 Prometheus 上时,我看到许多与 CPU 相关的指标,但不确定该选择哪一个:

prom1

我尝试选择一个,但名称空间 = prometheus 并且它使用 prometheus-node-exporter,而且我在这里的任何地方都看不到我的集群或名称空间 test1

prom2

你能帮帮我吗?非常感谢您。

更新屏幕截图 更新屏幕截图 我需要专注于这个特定的命名空间,通常使用以下命令: kubectl get pods --all-namespaces | grep hermatwin 我看到第一行有 namespace = jobs 我认为这是命名空间。

将日历设置为上周五时没有结果:

4 月 20 日更新屏幕截图 我尝试 select 2 天,开始日期是 4 月 17 日上周六,但我没有看到任何结果:

而且,如果我删除 (namespace="jobs") 条件,我也看不到任何结果:

我刚才再次尝试重新运行作业(模拟作业)并尝试在作业仍处于 运行 模式时执行 prometheus 查询,但我没有得到任何结果:-( 在这里你可以查看我的工作 运行.

我没有得到任何结果:

使用简单过滤器时,只需 container_cpu_usage_seconds_total,我就能看到 namespace="jobs"

node_cpu_seconds_total 是来自 node-exporter 的指标,提供机器统计信息的导出器及其指标以 node_ 为前缀。您需要来自 cAdvisor 的指标,这个指标生成与容器相关的指标,它们以 container_:

为前缀
container_cpu_usage_seconds_total
container_cpu_load_average_10s
container_memory_usage_bytes
container_memory_rss

这里有一些基本的查询供您开始使用。准备好它们可能需要调整(您可能有不同的标签名称):

CPU 每个 Pod 的利用率

sum(irate(container_cpu_usage_seconds_total{container!="POD", container=~".+"}[2m])) by (pod)

每个 Pod 的 RAM 使用量

sum(container_memory_usage_bytes{container!="POD", container=~".+"}) by (pod)

In/Out 每个 Pod 的流量率

注意 pods 和 host 网络模式(未隔离)显示整个节点的流量速率。 * 8是为了方便将字节转换为位(MBit/s、GBit/s等)。

# incoming
sum(irate(container_network_receive_bytes_total[2m])) by (pod) * 8
# outgoing
sum(irate(container_network_transmit_bytes_total[2m])) by (pod) * 8