PromQL : Using wildcards in metric names for topk

Viewed 3270

I am sending Metrics to Prometheus and I am able to visualize their values using PromQL in Grafana. Here's an example:

topk(1, package_class_method_mean{domain="my_domain", asset="my_asset"})

Now, this shows me the graphs fine. However, what I want to do is to sort all the metrics in descending order of mean, something like:

topk(10, *_mean{domain="my_domain", asset="my_asset"})

How can I do that using PromQL?

Edit

I have tried the below query:

topk(10, {__name__=~"_mean"}{domain="my_domain", asset="my_asset"})

However, that gives me ParseException saying unexpected { in the aggregation.

1 Answers

Use the following:

topk(10, {__name__=~".*_mean", domain="my_domain", asset="my_asset"})
Related