influxdb 中基于时间的条件

Time based conditions in influxdb

我正在试验 InfluxDB,并得到以下行为: 在创建了几行具有任意内容的行之后,我选择了中间行的时间值 ts 并查询:select * from test where time > ts.

出于某种原因,这 returns 所有行,包括具有较低时间戳的行。我是否误解了时间限制的语法?

附带说明一下,如果我以分钟为间隔创建行,并使用条件 where time > now() -1m 我只会获取最后一分钟创建的行。

来自 InfluxDB 站点 query language 文档:

Note that the time is a very large number. That’s because it’s a microsecond scale epoch. InfluxDB always stores points at this scale, but most libraries will return the time as either a second, or millisecond scale value. If you’re selecting a specific point, you’ll need to know the exact microsecond scale epoch that point has otherwise you’ll get an unexpected empty result.

现在,使用 Influx 附带的默认 Web 界面,您可以看到像 1422883121396 这样的时间戳,而在上面的教程中您可以看到 1400497861762723!第二个时间戳有更多的数字,实际上是微秒级(不完整,显示了 3 个,而应该是 6 个)。因此,像 time > 1422883121396 这样的查询是在查询一个非常旧的 date/time,因此会返回所有结果。

解决方案:

  1. 使用 returns 完整时间戳的库,但是,我从未使用过,所以我不知道

  2. 如果您真的不关心微秒精度,并且作为解决方法,您可以在时间戳末尾添加 000000 以将其转换为正确的刻度

有些应用程序可能需要这种精度(例如模拟软件),但在大多数情况下,#2 解决方法应该可行。

希望以上能解决您的问题