English 中文(简体)
Omit labels from series results PromQL
原标题:

Suppose I write a basic PromQL query like this

Query: kube_deployment_spec_replicas{}

Result: kube_deployment_spec_replicas{deployment="mydeployment",endpoint="myendpoint",instance="myinstance",job="myjob",namespace="default",pod="mypod",service="myservice"}

Is there a clean way to omit instance and pod from the resulted timeseries?

Desired: kube_deployment_spec_replicas{deployment="mydeployment",endpoint="myendpoint",job="myjob",namespace="default",service="myservice"}

问题回答

Try using something like the following as Sergio already suggested:

sum(kube_deployment_spec_replicas) without (instance, pod)

This query will remove instance and pod labels from the result. Note that the query won t work as expected if there are multiple kube_deployment_spec_replicas time series with identical (instance, pod) set of labels. In this case the query will sum up these time series.

p.s. MetricsQL - PromQL-like query language from Prometheus-like monitoring system - VictoriaMetrics - provides more obvious solution to delete labels with label_del function:

label_del(kube_deployment_spec_replicas, "instance", "pod")

Disclosure: I m the author of VictoriaMetrics.

You need to use Prometheus query operators. You can use avg or sum depending on your use case.

You can check here for more information: here

Try sum by (labelName), eg:

sum by (job) (
  rate(http_requests_total[5m])
)

This will aggregate all http_requests_total metric by its job label.

Doc: https://prometheus.io/docs/prometheus/latest/querying/examples/#:~:text=we%20might%20want%20to%20sum%20over%20the%20rate%20of%20all%20instances





相关问题
Prometheus Java client manually exposing prometheus end point

I have a spring boot application where for certain legacy reasons I cannot use spring actuator. I was able to expose a prometheus end point and see a lot of default metrics. But I am not able to see ...

Grafana interval variable: minimum threshold function?

I m adding an interval variable to a dashboard to allow averaging some prometheus time series over an interval to get cleaner looking graphs. But I want to leave in the base sample rate (15s) so the ...

How to specify time range in {aggregate}_over_time?

I have a Grafana chart that makes use of the sum_over_time(data_source[$__interval]) and count_over_time(data_source[$__interval]) command in Prometheus. Normally, it is working fine. But, the ...

how to regex path in prometheus relabel_configs

i have a metric and label like this: namedprocess_namegroup_num_procs{groupname:"/data/home/user01/app.service.1/service"}, i want to get the last field: service, and the number in last but ...

Omit labels from series results PromQL

Suppose I write a basic PromQL query like this Query: kube_deployment_spec_replicas{} Result: kube_deployment_spec_replicas{deployment="mydeployment",endpoint="myendpoint",instance="myinstance",...

Last known timestamp of a metric sample?

How do I get the timestamp of the last known sample of a metric? I want to display a table that lists when was the last time a specific service was running before it disappeared (died or whatever). ...

热门标签