Search code examples
prometheusgrafanametricspromql

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{somelabel="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{somelabel="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

  • timestamp(my_device_time) - my_device_time()
    

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