Reputation: 135
I am reading kube-prometheus, https://github.com/coreos/kube-prometheus and came across a PromQL in a Prometheus rule file which I am having hard time understanding.
sum(namespace:kube_pod_container_resource_requests_cpu_cores:sum)
in here https://github.com/coreos/kube-prometheus/blob/master/manifests/prometheus-rules.yaml#L673
But similarly this
sum(container:kube_pod_container_resource_requests_cpu_cores:sum)
doesn't return anything where 'container' is just a label like 'namespace'
This is how the instant vector looks like for "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"}
Can someone explain to me how's this working and were in the PromQL documentation it's mentioned to do this kind of query?
Can we do a query like this "label:metric:function"?
Thanks
Upvotes: 1
Views: 450
Reputation: 13516
You cannot query like, "label:metric:function".
namespace:kube_pod_container_resource_requests_cpu_cores:sum
is nothing but a name of a Prometheus 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
So, whenever you create a new rule, Prometheus creates a new time series metric named after the rule name (i.e. namespace:kube_pod_container_resource_requests_memory_bytes:sum
).
If you want to query something like container:kube_pod_container_resource_requests_cpu_cores:sum
, you need to record a rule first by this name.
NB:
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.
Upvotes: 3