kubernetes 获取所有命名空间的内存使用百分比

f87krz0w  于 2023-03-01  发布在  Kubernetes
关注(0)|答案(1)|浏览(184)

我有这样的疑问:

100 * (1 - ((avg_over_time(node_memory_MemFree_bytes[10m]) + avg_over_time(node_memory_Cached_bytes[10m]) + avg_over_time(node_memory_Buffers_bytes[10m])) / avg_over_time(node_memory_MemTotal_bytes[10m])))

但是,它只返回安装Prometheus的名称空间:

{instance="10.240.0.11:9100", job="kubernetes-service-endpoints", kubernetes_name="node-exporter", kubernetes_namespace="monitoring"}
5.58905365516873
{instance="10.240.0.11:9100", job="node-exporter"}
5.588556605118522
{instance="10.240.0.42:9100", job="kubernetes-service-endpoints", kubernetes_name="node-exporter", kubernetes_namespace="monitoring"}
5.093870850709847
{instance="10.240.0.42:9100", job="node-exporter"}
5.09401539556571
{instance="10.240.0.90:9100", job="kubernetes-service-endpoints", kubernetes_name="node-exporter", kubernetes_namespace="monitoring"}
5.103046564234582
{instance="10.240.0.90:9100", job="node-exporter"}

是否有可能有一个类似的查询,查询整个集群,所有节点和命名空间?如果有,如何?

guykilcj

guykilcj1#

将节点导出器安装为daemonset后,您就拥有了整个集群的指标。
要获得群集内存的总体使用情况(以百分比表示):

100 * (
 sum(node_memory_MemTotal_bytes{service="node-exporter"}) -
 sum(node_memory_MemAvailable_bytes{service="node-exporter"})
) / sum(node_memory_MemTotal_bytes{service="node-exporter"})

结果,例如:

{}   37.234674067149946

节点的内存使用情况:

100 * (
 sum by (instance) (node_memory_MemTotal_bytes{service="node-exporter"}) - 
 sum by (instance) (node_memory_MemAvailable_bytes{service="node-exporter"})
) / sum by (instance) (node_memory_MemTotal_bytes{service="node-exporter"})

结果,例如:

{instance="x.x.x.x:9100"}   42.51742364002058
{instance="y.y.y.y:9100"}   38.26956501095188
{instance="z.z.z.z:9100"}   36.57150031634585

特定命名空间的内存使用情况:

100 * sum(container_memory_working_set_bytes{namespace="my-namespace"}) / 
sum(node_memory_MemTotal_bytes)

结果,例如:

{} 4.212481093513011

相关问题