【问题标题】:influxdb 1.X group by time query does not workinfluxdb 1.X 按时间分组查询不起作用
【发布时间】:2021-01-13 02:00:11
【问题描述】:

我正在使用 influxdb 1.7

我有一个名为“测试”的测量,如下所示

> 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

我还可以将其按标签值分组,例如 ...

> 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

但是当我在查询中添加time(1m) 条件时,它什么也不返回。 我想知道在这种情况下我应该检查什么。

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

谢谢

【问题讨论】:

    标签: group-by time-series influxdb


    【解决方案1】:

    我发现了问题所在。事实上,时间戳是错误的。现在是 UTC 时间。我已经从 python-client 中放入了这些数据,它需要额外的转换。

    我在 +09 区。所以...时间戳表示从现在起 9 小时后。

    我更改了我的 python3 代码

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

    datetime_stamp 变量是 python 中的 datetime 类型

    【讨论】:

    • 结论:检查时区
    猜你喜欢
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多