4

In Prometheus sometimes we need to plot several metrics at onces (say, having name, fitting the same regex) like that PromQL query:

{name=~"camel_proxy.*count"}

and it works fine, the same labelset lines are plotted with the different names.

When we want to plot the rate() of them, we face the error from the title:

rate({name=~"camel_proxy.*count"}[5m])

So, the way here is to make labelset not the same, and to move the __name__ to some label, making each labelset to be unique:

rate(label_replace({name=~"camel_proxy.*count"},"name_label","$1","name", "(.+)")[5m])

But we are still getting the error like

1:90: parse error: ranges only allowed for vector selectors"

How to avoid it and plot the rates correctly?

2
  • 1
    I found I had to use __name__ instead of name in the query that Ilya shared here - both in the metric-selector at the start, and also in the label_replace function as follows: label_replace({__name__=~"camel_proxy.*count"},"name_label","$1","__name__", "(.+)") (I tried to update the question itself with an edit, but the edit-queue on Stack Overflow was full 😢)
    – samjewell
    Nov 29, 2021 at 15:49
  • This doesn't work for me I get the same error.
    – jayarjo
    Jul 27, 2022 at 19:11

2 Answers 2

6

The PromQL query here should be

rate(label_replace({name=~"camel_proxy.*count"},"name_label","$1","name", "(.+)")[5m:])

please note 5m**:** instead of 5m

0

The label_replace() inside rate() triggers subquery processing, which may return unexpected results, since the rate() starts working with calculated samples returned from label_replace() instead of raw samples stored in the database.

MetricsQL at VictoriaMetrics (this is Prometheus-like monitoring solution I work on) provides more elegant solution for vector cannot contain metrics with the same labelset error - keep_metric_names modifier. Just put this modifier after the function, which strips metric names, in order to instruct it to keep metric names:

rate({name=~"camel_proxy.*count"}[5m]) keep_metric_names

This solution avoids triggering subquery processing, so the rate() function continues working on raw samples stored in the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.