Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter prometheus query by label value using greater-than

If I have matrics like this

my_metric{deployTime="1603284798",foo='bar'}
my_metric{deployTime="1603284799",foo='bar2'}
my_metric{deployTime="1603284800",foo='bar3'}

And I want to get only the metrics where the timestamp is greater than some value, how can I do it?

I was thinking of:

count by (deployTime, foo) (my_metric{deployTime > "1603284799", foo=~".*"})

but of course, this doesn't work as labels are strings. So what are my options to filter by label value if I want to use the greater than operator?

like image 892
Gerardo Avatar asked Dec 30 '25 00:12

Gerardo


1 Answers

I don't know if I understood correctly but, do you have a label called "timestamp"? This seems to be unnecessary.

I think you can achieve what you want with the following query:

count by (foo) (timestamp(my_metric)>1603284799)

UPDATE

After you have clarified your question the answer is: unfortunately you can't query for labels using "greater than", "less than", etc.

like image 96
Marcelo Ávila de Oliveira Avatar answered Jan 04 '26 07:01

Marcelo Ávila de Oliveira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!