Trying to get the delta between 2 datapoints (surely I'm missing something here )

Hi ,
I have a query that give me several metrics like

active_readers_count_receiving_readers_cnt_20_98 
active_readers_count_receiving_readers_cnt_20_99
active_readers_count_receiving_readers_cnt_30_45

I want for each metric to alert if there was a change between the kast value and the previous one .
I tried this :
delta({__name__=~"active_readers_count_receiving_readers_cnt.*"}[10m])
got an error:

vector cannot contain metrics with the same labelset

So I tried to replace the label using label_replace:
deltae(label_replace({__name__=~"active_readers_count_receiving_readers_cnt.*"}, "metric_name", "$1", "__name__", "(.*)")[10m])

but got this error :

bad_data: invalid parameter “query”: 1:122: parse error: ranges only allowed for vector selectors

I tried to play with it with no success .
It seems like basic stuff and i’m not sure what I’m missing here .

anyone ?

Hi @zvikagutkin and welcome to the Grafana forum, and sorry that nobody has responded thus far.

Just for kicks, does this work? This query should return a value of 1 if there was a change in the metric value between the last two samples, and a value of 0 if there was no change.
delta(active_readers_count_receiving_readers_cnt_20_98[1m])

If it works, then I guess it just means that one has to determine the syntax to have the query apply to all metrics (which is what I can see you tried). Maybe this?

delta(active_readers_count_receiving_readers_cnt_\d{2}_\d{2}[1m])

This query uses the regular expression active_readers_count_receiving_readers_cnt_\d{2}_\d{2} to match any metric that starts with active_readers_count_receiving_readers_cnt_ , followed by two digits, two more digits, and an underscore. The [1m] range vector specifies that the delta should be calculated over the last minute.

This query should work for any metric that follows the format of the provided metrics and will return an instant vector with a value of 1 if there was a change in the metric value between the last two samples, and a value of 0 if there was no change.

Thanks for the reply
the specific query works
the regex query you suggested gave me an error but this one worked
{name=~“active_readers_count_receiving_readers_cnt_."}
but when I add the delta function:
delta({name=~"active_readers_count_receiving_readers_cnt_.
”}[5m])
gives an error:
vector cannot contain metrics with the same labelset

that’s why I tried to add label_replace but that didn’t work also

What was the error?

the error was

bad_data: invalid parameter "query": 1:50: parse error: unexpected character: '\\'

That gave me the error that I wrote about

delta({__name__=~"active_readers_count_receiving_readers_cnt_\\d{2}_\\d{2}"}[1m])