【问题标题】:Find min/max/average memory used by pod using promethus使用 prometheus 查找 pod 使用的最小/最大/平均内存
【发布时间】:2021-06-16 07:48:39
【问题描述】:

我正在尝试查找特定 pod 在一段时间内消耗的最小/最大/平均内存。

目前我正在使用

sum(container_memory_working_set_bytes{namespace="test", pod="test1", container!="POD", container!=""}) by (container)

Output -> test1 = 9217675264

出于报告目的,我需要找到 pod 在一段时间内(6h)使用的最小/峰值内存 也很平均。

【问题讨论】:

    标签: kubernetes prometheus


    【解决方案1】:

    您可以使用范围向量(将[interval] 添加到度量名称/选择器)和aggregation-over-time function

    min_over_time(container_memory_usage_bytes{}[6h])
    max_over_time(container_memory_usage_bytes{}[6h])
    avg_over_time(container_memory_usage_bytes{}[6h])
    

    【讨论】:

    • 谢谢。我们有办法将输出值转换为 GB 吗?现在,我得到 8944175025 作为输出(这意味着 8.9GB?)
    • @pythonhmmm 没有“魔术”功能,但您可以使用数学:avg_over_time(container_memory_usage_bytes{}[6h])/(2^30)
    • 谢谢。还有一个问题。我可以减少/过滤输出吗?目前我得到 {container="cont1",endpoint="http",instance=":8080",job="kube-state-metrics",namespace="test",node="node_name",pod="pod_name" ,service="monitoring-kube-state-metrics"} 和值。是否有可能只获得 { pod_name : value } 类似的东西。
    • @pythonhmmm sum by(pod_name) (min_over_time(container_memory_usage_bytes{}[6h])) 这将导致{pod_name="some_name"} 123。这可能是我能想到的最接近您所要求的内容。如果您想要类似 json 的内容,请考虑使用 api
    猜你喜欢
    • 2020-06-17
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 2015-01-16
    • 1970-01-01
    • 2022-10-26
    相关资源
    最近更新 更多