InfluxDB2时序数据库查询教程
1. 定义数据源(from)
from(bucket:"example-bucket")
2. 时间范围(range)
- 最近12小时
from(bucket:"example-bucket")
|> range(start: -12h)
- 最近3天
from(bucket:"example-bucket")
|> range(start: -3d)
- 起止时间
from(bucket:"example-bucket")
|> range(start: 2021-01-01T00:00:00Z, stop: 2021-01-01T12:00:00Z)
3. 过滤条件(filter)
from(bucket: "example-bucket")
|> range(start: -15m)
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total")
4. 统计函数
InfluxDB 常用的数据统计(聚合)模式主要包括以下几种,适用于 InfluxQL 和 Flux 查询语言:
- 中位数(Median)
- InfluxQL: median("field")
- Flux: median()
- 平均值(Average/Mean)
- InfluxQL: mean("field")
- Flux: mean()
- 最大值(Max)
- InfluxQL: max("field")
- Flux: max()
- 最小值(Min)
- InfluxQL: min("field")
- Flux: min()
- 求和(Sum)
- InfluxQL: sum("field")
- Flux: sum()
- 计数(Count)
- InfluxQL: count("field")
- Flux: count()
- 首值/末值(First/Last)
- InfluxQL: first("field"), last("field")
- Flux: first(), last()
- 标准差(Stddev)
- InfluxQL: stddev("field")
- Flux: stddev()
- 方差(Variance)
- InfluxQL: variance("field")
- Flux: variance()

浙公网安备 33010602011771号