配置类@Data@ConfigurationProperties(prefix = "influxdb")@Componentpublic class InfluxdbConfigProp { private String token; private String bucket; private String org; private String url;}@Configurationpublic class InfluxdbConfig { @Autowired private InfluxdbConfigProp influxdbConfigProp; @Bean public InfluxDBClient influxDBClient() { InfluxDBClient influxClient = InfluxDBClientFactory.create( influxdbConfigProp.getUrl(), influxdbConfigProp.getToken().toCharArray()); influxClient.setLogLevel(LogLevel.BASIC); return influxClient; } @Bean public WriteApi writeApi(InfluxDBClient influxDBClient) { WriteOptions writeOptions = WriteOptions.builder() .batchSize(5000) .flushInterval(1000) .bufferLimit(10000) .jitterInterval(1000) .retryInterval(5000) .build(); return influxDBClient.getWriteApi(writeOptions); } @Bean public QueryApi queryApi(InfluxDBClient influxDBClient) { return influxDBClient.getQueryApi(); }}常用函数window()使用window()函数根据时间界限对数据进行分组 。window()传递的最常用参数是every,它定义了窗口之间的持续时间 。也可以使用其他参数,但是对于本例 , 将基本数据集窗口化为一分钟窗口 。dataSet |> window(every: 1m)
first()和last()获取查询结果的第一条或最后一条
drop()删除查询结果的指定列|> drop(columns: ["host"])
sort()和limit()排序和分页|> sort(columns: ["index", "time"], desc: true)|> limit(n: 10)n参数为pageSize
timedMovingAverage()对于表中的每一行,timedMovingAverage()返回当前值和上一个周期(持续时间)中所有行值的平均值 。它以每个参数定义的频率返回移动平均线 。|> timedMovingAverage(every: 1h, period: 1h)
aggregateWindow()|> aggregateWindow(every: 1h, fn: first, createEmpty: true)每一小时时间片的第一条记录,空数据以null填充
map()|> map( fn:(r) => { return { code: r["code"], time: r["_time"], value: r["_value"], index: r["indexName"] } } )注意事项
- tag与tag之间用逗号分隔
- field与field之间用逗号分隔
- tag与field之间用空格分隔
- tag都是string类型,不需要引号将value包裹
- tag的值不能有空格
- 写入数据时,若tag和时间戳都相同的多条记录,则最后只会保存一条
推荐阅读
- Deepin系统navicat15安装
- 手把手教你玩转 Gitea|使用 Docker 安装 Gitea
- Docker搭建kafka及监控
- VMware安装Win11+WSA子系统和使用教程
- 大华海康NVR录像JAVA下载及WEB播放
- Linux make编译
- 为什么下载不了小红书 小红书为什么下载不了
- 三星GT-N7102救砖步骤
- 如何安装iis软件 如何安装IIS?
- 怎样安装iis组件 怎样安装IIS