query.inBucket() 函数
query.inBucket() 是实验性的,随时可能更改。
query.inBucket() 从指定的 InfluxDB bucket 查询给定时间范围内的数据,
通过测量、字段和可选谓词表达式过滤数据。
函数类型签名
(
bucket: string,
measurement: A,
start: B,
?fields: [string],
?predicate: (
r: {
C with
_value: D,
_time: time,
_stop: time,
_start: time,
_measurement: string,
_field: string,
},
) => bool,
?stop: E,
) => stream[{
C with
_value: D,
_time: time,
_stop: time,
_start: time,
_measurement: string,
_field: string,
}] where A: Equatable
有关更多信息,请参见 Function type signatures。
参数
桶
(必需) InfluxDB 存储桶名称。
测量
(必需) 按 InfluxDB 测量名称进行过滤。
开始
(必填) 包含在结果中的最早时间。
结果包括匹配指定开始时间的点。
使用相对持续时间、绝对时间或整数(以秒为单位的Unix时间戳)。
例如, -1h、 2019-08-28T22:00:00Z,或 1567029600。
持续时间相对于 now()。
停止
最新包含在结果中的时间。默认值是 now()。
结果不包括与指定停止时间匹配的点。 使用相对持续时间、绝对时间或整数(以秒为单位的Unix时间戳)。例如, -1h, 2019-08-28T22:00:00Z,或 1567029600。 持续时间相对于 now()。
字段
过滤字段。默认值是 []。
断言
谓词函数,用于评估列值并返回 true 或 false。默认值是 (r) => true。
记录 (r) 被传递给函数。
那些评估为 true 的记录被包含在输出表中。
评估为 null 或 false 的记录不包含在输出表中。
示例
从InfluxDB查询测量中的特定字段
import "experimental/query"
query.inBucket(
bucket: "example-buckt",
start: -1h,
measurement: "mem",
fields: ["field1", "field2"],
predicate: (r) => r.host == "host1",
)