用prometheus计算k8s集群的CPU/内存使用率 [英] count k8s cluster cpu/memory usage with prometheus

查看:3219
本文介绍了用prometheus计算k8s集群的CPU/内存使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用普罗米修斯计算k8s集群的cpu/内存使用量(不是k8s pod的使用量),以便可以在grafana中显示.

I want to count k8s cluster cpu/memory usage (not k8s pod usage) with prometheus, so that i can show in grafana.

我使用sum (container_memory_usage_bytes{id="/"})来获取k8s集群使用的内存,并使用topk(1, sum(kube_node_status_capacity_memory_bytes) by (instance))来获取整个k8s集群使用的内存,但是由于topk函数不返回值而是返回向量,因此它们无法划分.

I use sum (container_memory_usage_bytes{id="/"}) to get k8s cluster used memory, and topk(1, sum(kube_node_status_capacity_memory_bytes) by (instance)) to get whole k8s cluster memory, but they can not divide since topk function does not return value but vector.

我该怎么做?

推荐答案

我的主要问题是topk(1, sum(kube_node_status_capacity_memory_bytes) by (instance))无法返回值,但是现在我发现使用sum()隐蔽它可以工作,整个查询如下:

My main qustion is that topk(1, sum(kube_node_status_capacity_memory_bytes) by (instance)) can not return a value, but now i find that use sum() to covert it can work, whole query as following:

sum(sum (container_memory_usage_bytes{id="/"})by (instance))/sum(topk(1, sum(kube_node_status_capacity_memory_bytes) by (instance)))*100

这篇关于用prometheus计算k8s集群的CPU/内存使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆