Influxdb2:如何在同一桶中的不同测量中对数据进行下采样?

Influxdb2 : How to downsample data in a different measurement in same bucket?

我想在 同一个存储桶 中创建包含月度数据的聚合度量。目前我有一个关于这个查询的任务:

import "strings"

option task = {name: "MTU Monthly", every: 1d}

from(bucket: "my_bucket")
    |> range(start: 1464943523, stop: 1654244985)
    |> filter(fn: (r) => r._measurement == "machine_time_utilization")
    |> aggregateWindow(every: 1mo, fn: sum)
    |> map(
        fn: (r) =>
            ({r with _measurement:
                    strings.replaceAll(
                        v: r._measurement,
                        t: "machine_time_utilization",
                        u: "machine_time_utilization_monthly",
                    ),
            }),
    )
    |> to(bucket: "my_bucket")

我不喜欢 strings.replaceAll 的处理方式。有什么办法可以做得更好吗?

如果需要在记录中设置静态值,使用set函数,即

from(bucket: "my_bucket")
    ...
    |> aggregateWindow(every: 1mo, fn: sum)
    |> set(key: "_measurement", value: "machine_time_utilization_monthly")
    |> to(bucket: "my_bucket")