Search code examples
group-bytime-seriesinfluxdb

influxdb 1.X group by time query does not work


I am working with influxdb 1.7

I have a measurement named "test" like below

> SELECT * FROM test
name: test
time                code    host        f_range         value
----                ---     ----        -------         -----
1610532240000000000 a       localhost   0.101~0.200     7
1610532240000000000 a       localhost   0.401~0.500     1
1610532240000000000 b       localhost   0.101~0.200     3
1610532300000000000 b       localhost   0.101~0.200     3
1610532300000000000 b       localhost   0.201~0.300     1
1610533020000000000 a       localhost   0.101~0.200     4
1610533020000000000 a       localhost   0.201~0.300     1
1610533020000000000 a       localhost   0.401~0.500     1
1610533020000000000 b       localhost   0.101~0.200     6
1610533620000000000 a       localhost   0.101~0.200     11
1610533620000000000 b       localhost   0.101~0.200     8

And I can also make it group by tag values like ...

> SELECT sum("value") FROM "test" WHERE ("code" =~ /^a$/ AND "host" =~ /^localhost$/) AND time >= now() - 30m GROUP BY "f_range" fill(0)
name: test(0)
tags: f_range=0.101~0.200
time                sum
----                ---
1610500909884441460 22

name: test
tags: f_range=0.201~0.300
time                sum
----                ---
1610500909884441460 1

name: test
tags: f_range=0.401~0.500
time                sum
----                ---
1610500909884441460 2

But when I add time(1m) condition to the query it just return nothing. I wonder what should I have to check in this case.

> SELECT sum("value") FROM "test" WHERE ("code" =~ /^a$/ AND "host" =~ /^localhost$/) AND time >= now() - 30m GROUP BY time(1m), "f_range" fill(0)
>

Thanks


Solution

  • I found what was wrong. In fact the timestamp was wrong. It is UTC time. I have put those data from python-client and it needs extra conversion.

    I am in +09 Zone. So... the timestamp states the 9 hours after from now.

    I changed my python3 code

    single = {'measurement':'test', 'tags': tags, 'time': date_timestamp.strftime('%Y-%m-%dT%H:%M:%S+09'), 'fields': {'value': value}} 
    

    datetime_stamp variable is a datetime type in python