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

huangapple go评论71阅读模式
英文:

Get percentual of memory usage across all namespaces

问题

我有这个查询:

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"}

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

英文:

I have this query:

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])))

However it only returns the namespace where Prometheus is installed:

{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"}

Is it possible to have a similar query that queries the entire cluster, all nodes and namespaces? If yes, how?

答案1

得分: 3

使用作为守护程序安装的 node-exporter,您可以获得整个集群的指标。

要获取整个集群内存使用率(以百分比表示):

 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```

<details>
<summary>英文:</summary>

With the node-exporter installed as daemonset, you have the metrics of the entire cluster.

To have the overall cluster memory usage, in percentage:

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"})

Result, for example:

{} 37.234674067149946


Memory usage by node:

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"})

Result, for example:

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


Memory usage for a specific namespace:

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


Result, for example:

{} 4.212481093513011


</details>



huangapple
  • 本文由 发表于 2023年2月23日 19:36:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544287.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定