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?
22 Answers
The PromQL query here should be
rate(label_replace({name=~"camel_proxy.*count"},"name_label","$1","name", "(.+)")[5m:]) please note 5m**:** instead of 5m
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.
ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobXFxZGl9cXyOoaawZaSkeqLCzqKbZq6VmMGwvoycmKemn6l6pLvNrZiipl2isrW%2ByJyqZq%2BZqbVuwMeeZKyZnZp6ra3BnqOsnaRisrO%2BzqtksKCVo3qx