Grafana filter by unixtimestamp using influxdb datasource


Hi. I’m trying to use a timestamp(ms since 1970) in the query below

SELECT “usage_idle” FROM cpu where time = 1504909620000

Is it possible?

Thank you


Yes, is the short answer but with time = 1504909620000 you will at most get one data point. You could change it to time >= 1504909620000 to get all metrics with a timestamp greater than that date.

Is this a special query or why not just use the inbuilt time range functions in Grafana?

Here is a similar query in raw query mode in Grafana. The $timeFilter variable is the time range that is chosen in the Grafana datepicker:

SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null) ORDER BY time DESC

This gets translated to the real query:

SELECT mean("value") FROM "cpu" WHERE time >= now() - 30m GROUP BY time(10s) fill(null) ORDER BY time DESC