Jul*_*iën 6 flux influxdb influxdb-2
我正在努力处理 Flux 中的 Influx 2 查询,了解如何将两个不同集(表)中的数据连接和映射到特定的所需输出。
我当前的 Flux 查询是这样的:
data = from(bucket: "foo")
|> range(start:-1d)
|> filter(fn: (r) => r._measurement == "io")
|> filter(fn: (r) => r["device_id"] == "12345")
|> filter(fn: (r) => r._field == "status_id" )
# count the total points
totals = data
|> count(column: "_value")
|> toFloat()
|> set(key: "_field", value: "total_count")
# calculate the amount of onlines points (e.g. status = '1')
onlines = data
|> filter(fn: (r) => r._value == 1)
|> count(column: "_value")
|> toFloat()
|> set(key: "_field", value: "online_count")
union(tables: [totals, onlines])
Run Code Online (Sandbox Code Playgroud)
这将作为输出返回:
[{'online_count': 58.0}, {'total_count': 60.0}]
Run Code Online (Sandbox Code Playgroud)
我想在此输出中附加一个由此计算出的百分比。就像是:
[{'online_count': 58.0}, {'total_count': 60.0}, {'availability': 0.96666667}]
Run Code Online (Sandbox Code Playgroud)
我尝试使用.map()组合它,但无济于事:
# It feels like the map() is what I need, but can't find the right
# combination with .join/union(), .map(), .set()., .keep() etc.
union(tables: [totals, onlines])
|> map(fn: (r) => ({ r with percentage_online: r.onlines.online_count / r.totals.total_count * 100 }))
Run Code Online (Sandbox Code Playgroud)
如何在此 Flux 查询中附加(计算出的)百分比作为新字段“可用性”?
或者,是否有不同的 Flux 查询方法来实现此结果?
注意,我知道文档中的“使用 Flux 计算百分比”一文,但我无法将其应用于此特定场景。但已经很接近了。
归档时间: |
|
查看次数: |
1428 次 |
最近记录: |