PromqQL 中的 label:metric:function 是什么?

What's label:metric:function in PromqQL?

我正在阅读 kube-prometheus,https://github.com/coreos/kube-prometheus 并在 Prometheus 规则文件中遇到了一个我很难理解的 PromQL。

sum(namespace:kube_pod_container_resource_requests_cpu_cores:sum)

在这里https://github.com/coreos/kube-prometheus/blob/master/manifests/prometheus-rules.yaml#L673

但同样如此

sum(container:kube_pod_container_resource_requests_cpu_cores:sum)

不会 return 任何 'container' 只是像 'namespace'

这样的标签

这是 "kube_pod_container_resource_requests_cpu_cores"

的即时向量的样子
kube_pod_container_resource_requests_cpu_cores{container="kube-controller-manager",instance="172.17.0.7:8080",job="kube-state-metrics",namespace="kube-system",node="minikube",pod="kube-controller-manager-minikube"}  

有人可以向我解释这是如何工作的吗?在 PromQL 文档中提到它可以执行这种查询吗?

我们可以这样查询吗"label:metric:function"?

谢谢

You cannot query like, "label:metric:function".

namespace:kube_pod_container_resource_requests_cpu_cores:sum不过是普罗米修斯的名字rule which is define in here.

    - expr: |
        sum by (namespace) (
            sum by (namespace, pod) (
                max by (namespace, pod, container) (
                    kube_pod_container_resource_requests_memory_bytes{job="kube-state-metrics"}
                ) * on(namespace, pod) group_left() max by (namespace, pod) (
                    kube_pod_status_phase{phase=~"Pending|Running"} == 1
                )
            )
        )
      record: namespace:kube_pod_container_resource_requests_memory_bytes:sum

因此,每当您创建新规则时,Prometheus 都会创建一个以规则名称命名的新时间序列指标(即 namespace:kube_pod_container_resource_requests_memory_bytes:sum)。

如果你想查询类似container:kube_pod_container_resource_requests_cpu_cores:sum的东西,你需要先用这个名字记录一条规则。

注意:

Recording rules should be of the general form level:metric:operations. level represents the aggregation level and labels of the rule output. metric is the metric name and should be unchanged other than stripping _total off counters when using rate() or irate(). operations is a list of operations that were applied to the metric, newest operation first.