InfluxDB Flux & Grafana 整合筆記
InfluxDB Flux & Grafana 整合筆記 留言
留言
基本查詢
from(bucket: "quote")
|> range(start: v.timeRangeStart, stop:v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "realtime" and
r.symbol == "${symbolSel}" and
r._field == "volume_24h"
)
from(bucket: "quote")
|> range(start: v.timeRangeStart, stop:v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "realtime" and
r.symbol == "${symbolSel}" and
r._field == "volume_24h"
)
兩個序列 join
join(tables: {t1: t1, t2: t2}, on: ["_time"])
|> map(fn: (r) => ({ r with _value: (r._value_t1 - r._value_t2)/r._value_t2 }))
|>map(fn: (r) => ({ r with alias: "120d 投資比" }))
join(tables: {t1: t1, t2: t2}, on: ["_time"])
|> map(fn: (r) => ({ r with _value: (r._value_t1 - r._value_t2)/r._value_t2 }))
|>map(fn: (r) => ({ r with alias: "120d 投資比" }))
pivot 同序列不同欄位 join
|> pivot(rowKey:["_time"], columnKey: ["valmean"], valueColumn: "_value")
|> map(fn: (r) => ({ r with _value: r.volume / r.open }))
|> pivot(rowKey:["_time"], columnKey: ["valmean"], valueColumn: "_value")
|> map(fn: (r) => ({ r with _value: r.volume / r.open }))
時間粗化
|> map(fn: (r) => ({ r with _time: date.truncate(t: r._time, unit: 1d) }))
|> map(fn: (r) => ({ r with _time: date.truncate(t: r._time, unit: 1d) }))
移動平均
By 個數
|> movingAverage(n: 2 )
|> movingAverage(n: 2 )
By 時間
|> timedMovingAverage(every: 1y, period: 5y)
|> timedMovingAverage(every: 1y, period: 5y)
Grafana 設定序列的title
在 Field > display name 設定 ${__field.labels.alias}
並且在該序列增加
|>map(fn: (r) => ({ r with alias: "顯示名稱" }))
留言
張貼留言