Flux 문법
2022. 2. 3. 10:51ㆍData
field 합계
_time 컬럼으로 group by를 수행하고,
_value로 값을 합침
aggregateWindow의 every 단위로 값의 mean하여 그래프로 보여줌
from(bucket: "nbminer")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mining")
|> filter(fn: (r) => r["_field"] == "hashrate")
|> group(columns: ["_time"], mode: "by")
|> sum(column: "_value")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "sum")
컬럼 추가하기
from(bucket: "nbminer")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mining")
|> filter(fn: (r) => r["_field"] == "hashrate")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> map(fn: (r) => ({ r with abc: r.device }))
|> yield(name: "mean")
filter 여러개 적용
from(bucket: "nbminer")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mining")
|> filter(fn: (r) => r["_field"] == "power" or r["_field"] == "hashrate")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
마지막 값 가져오기
정확한 값을 가져오기 위해서는 aggregateWindow를 빼야 함
from(bucket: "nbminer")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mining")
|> filter(fn: (r) => r["_field"] == "power")
|> filter(fn: (r) => r.device == "total")
//|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> last(column: "_time")
|> yield(name: "mean")
최대값 가져오기
from(bucket: "nbminer")
|> range(start: -2mo)
|> filter(fn: (r) => r["_measurement"] == "mining")
|> filter(fn: (r) => r["device"] == "total")
|> filter(fn: (r) => r["_field"] == "hashrate")
|> group(columns: ["device"], mode: "by")
|> max(column: "_time")
|> yield(name: "mean")
'Data' 카테고리의 다른 글
InfluxDB 연동 (0) | 2021.12.26 |
---|---|
Influxdb 설치 (0) | 2021.12.26 |
기상청 과거자로 URL (0) | 2019.11.18 |
기상청 과거 날씨 데이터 (0) | 2019.11.13 |
기상청 API URL (0) | 2019.11.09 |