deko
deko

Reputation: 350

How to query Prometheus vectors with specific value and with time offset?

In Prometheus, I want to query an instant vector in the past with value equals 1. Can I do that with PromQL or do I need to achieve it with recording rules?

Intuitively, I tried something like:

up{instance="192.168.0.100"} == 1 offset 30m

But it gives me the error: "Error executing query: invalid parameter 'query': parse error at char 39: offset modifier must be preceded by an instant or range selector, but follows a *promql.NumberLiteral instead"

I thought it was an operators order issue as the part before offset is an instant vector. So I added parentheses:

(up{instance="192.168.0.100"} == 1) offset 30m

But it gives another error: "Error executing query: invalid parameter 'query': parse error at char 34: could not parse remaining input "offset 30m"..."

So I'm asking if there is any way to get a vector that the value equals 1 at the time of 30 minutes ago? Do I must use recording rules to achieve this?

Upvotes: 2

Views: 8767

Answers (1)

vinodk
vinodk

Reputation: 829

Am not sure about your use-case, but try with something like this:

(up{instance="localhost:9090",job="prometheus"} offset 30m) == 1

Upvotes: 4

Related Questions