Alex Punnen
Alex Punnen

Reputation: 6244

PromQL Prometheus Query - How do we specify a data range in absolute terms

From Grafana Query inspector I am able to get the data for a date range ; Example

rate(node_disk_read_bytes_total{job="node-exporter",instance="172.18.0.2:9100",device=~"nvme.*"}[20m])

enter image description here

I can also give an absolute data time range. When I use the Prometheus GUI to query directly, I am not sure of the syntax of putting the date time range. I know it is in Unix Epoch time

What I have tried in PromQL from reading the docs

rate(node_disk_read_bytes_total{job="node-exporter",instance="172.18.0.2:9100",device=~"nvme.*"}[10m] @ 1648473649)[1d:10m]

1648473649 = Monday, 28 March 2022 13:20:49 https://www.epochconverter.com/

This works, without error and gives data, but the data is wrong (you can see from output it is giving one value all the way 38775.46666666667.

enter image description here

Also, I would like to give to and from as date timestamps in the above query.

The query which gives proper data in PromQL

rate(node_disk_read_bytes_total{job="node-exporter",instance="172.18.0.2:9100",device=~"nvme.*"}[10m])[7d:10m]

enter image description here

Upvotes: 1

Views: 14095

Answers (1)

valyala
valyala

Reputation: 18056

PromQL doesn't allow specifying time range for the query. Instead, the time range is specified via HTTP API args passed to the corresponding endpoints:

Such a design decision allows executing the same PromQL query at any timestamp or on any time range without the need to change the query itself.

Upvotes: 5

Related Questions