'Prometheus metric value compared to "crawl Time" in grafana

I have metric that exports "current time" from the device in UNIX time, now I would like to compare that time with "crawling time", but I seem to have some problems with that.

I tried multiple ways:

  1. Get "instant" data where unixtime is lower than the current time ( time() function )

example:

my_device_time{somelable="asd"} < (time() - 120)

Should return me rows that have a time difference of 2 or more minutes but do not seem to work.

The second (preferred way) would be something like that (in grafana):

    my_device_time{somelable="asd"} < (crawledTime() - 60)

So questions:

is it possible to get Time field as unixtimestamp for compare or how should i compare metric value (unixtime) against current timestamp with promql



Solution 1:[1]

timestamp(my_device_time) - my_device_time()

timestamp() will return crawl time in unixtime, so found the solution on my own.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1