0

我在 influxdb 中有以下数据

server,operation=ADD queryMs=7.9810 1620608972904452000
server,operation=GET queryMs=12.2430 1620608972909339200
server,operation=UPDATE queryMs=11.5780 1620608972909655400
server,operation=ADD queryMs=11.2460 1620608972910445700
server,operation=GET queryMs=15.0620 1620608972911305000
etc...

所以在我的图表中,我看到了三个系列 在此处输入图像描述

我想实现一个系列的所有operations。

我试过了|> group(columns: ["_field"]),这就是我需要的,但是查询非常慢!

from(bucket: "initial")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "server")
  |> filter(fn: (r) => r["_field"] == "queryMs")
  |> group(columns: ["_field"])
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

在此处输入图像描述 我的问题有什么快速解决方案吗?

4

1 回答 1

0

这工作得更快

union(tables: [
  from(bucket: "initial")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "server")
    |> filter(fn: (r) => r["_field"] == "queryMs")
    |> filter(fn: (r) => r["operation"] == "GET")
    |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false),
  from(bucket: "initial")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "server")
    |> filter(fn: (r) => r["_field"] == "queryMs")
    |> filter(fn: (r) => r["operation"] == "ADD")
    |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false),
  from(bucket: "initial")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "server")
    |> filter(fn: (r) => r["_field"] == "queryMs")
    |> filter(fn: (r) => r["operation"] == "UPDATE")
    |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false),
  ])
  |> drop(columns:["operation"])
  |> sort(columns: ["_time"], desc: false)
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")
于 2021-05-10T14:20:20.453 回答