我将InfluxDB与Grafana结合使用,并且有一个名为 的测量,items
其中包含一些标签和一个名为 的字段itemType
。我需要过滤itemType
某个字符串所在的行。以下 InfluxQL 查询正是我所需要的:
SELECT * FROM "items" WHERE "itemType" = 'example'
Run Code Online (Sandbox Code Playgroud)
我怎样才能在Flux中做同样的事情?
我目前有以下查询,它执行除按字段过滤之外的所有操作:
from(bucket: "dbname/autogen")
|> range(start: 2020-10-12T01:56:34Z, stop: 2020-10-12T02:54:10Z)
|> filter(fn:(r) => r._measurement == "items")
|> aggregateWindow(every: 5m, fn: count)
Run Code Online (Sandbox Code Playgroud)
但是用 替换该filter
函数filter(fn:(r) => r._measurement == "items" and r.itemType == "example")
不会返回任何结果,即使上面的 InfluxQL 查询在 InfluxDB CLI 中使用时确实返回数据。
小智 11
但是,如果itemType是标签,则指定的 Flux 查询将起作用,因为它是字段,使查询起作用的方法之一是对字段名称及其值设置条件,如下所示:
from(bucket: "dbname/autogen")
|> range(start: 2020-10-12T01:56:34Z, stop: 2020-10-12T02:54:10Z)
|> filter(fn:(r) => r._measurement == "items" and r._field == "itemType" and r._value == "example")
|> aggregateWindow(every: 5m, fn: count)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18281 次 |
最近记录: |