Flux script:
from(bucket:“myBucket”) |> range(start: 2024-05-01T00:00:00-07:00, stop: 2024-05-23T23:51:19-07:00) |> filter(fn: (r) => r._measurement == “data” and r._field == “Value” and (r.DeviceMetricId == “00001”)) |> aggregateWindow(every: 1h, fn: mean, createEmpty: false, timeSrc: “_start”) |> group(columns: [“_time”]) |> mean() |> keep(columns: [“_time”, “_value”])
Query execution method
import { InfluxDB, QueryApi } from ‘@influxdata/influxdb-client’;
async queryData(fluxQuery: string): Promise {
try {
const result = await this.queryApi.collectRows(fluxQuery);
return result;
} catch (error) {
throw Error(error);
}
}
Notes : I have accessed the production InfluxDB from my local API. It takes more than 1 second to execute the query. I am using Node.js for the API