influxdb 使用

您所在的位置:网站首页 redis主要用于什么场景 influxdb 使用

influxdb 使用

2023-12-19 03:49| 来源: 网络整理| 查看: 265

是什么

是使用Go语言编写的一个开源的时序型数据库,使用于海量时序数据的高性能读、高性能写、高效存储与实时分析等

时序数据库是一种按照时间存储的数据库。解决是海量数据的高效插入查询。主要应用在互联网的大规模数据统计分析上面,物联网的信息收集方面。 特点 部署简单、使用方便,无需任何外部依赖即可独立部署提供类似于SQL的查询语言提供灵活的数据保存策略来设置数据的保留时间和副本数,在保障数据可靠性的同时,及时删除过期数据,释放存储空间高性能读写及存储率丰富的聚合函数,支持AVG、SUM、MAX、MIN等聚合函数。 使用场景

主要使用于运维监控、物联网监控等场景,通过实现高度可扩展的数据接收和存储引擎,可以高效地实时收集、存储、查询、可视化显示和执行预定义操作

InfluxDB的写性能是MongoDB的2.4倍,存储效率是MongoDB的20倍,查询效率是MongoDB的5.7倍

使用

springboot集成influxdb

导包 com.github.miwurster spring-data-influxdb 1.8 yml配置 spring: influxdb: url: http://localhost:8086 username: user password: ~ database: test retention-policy: autogen # 保留策略 connect-timeout: 10 read-timeout: 30 write-timeout: 10 gzip: true #启用gzip压缩以减小传输数据的大小 Configuration配置 @Configuration @EnableConfigurationProperties(InfluxDBProperties.class) public class InfluxDBConfiguration { @Bean public InfluxDBConnectionFactory connectionFactory(final InfluxDBProperties properties) { return new InfluxDBConnectionFactory(properties); } @Bean public InfluxDBTemplate influxDBTemplate(final InfluxDBConnectionFactory connectionFactory) { return new InfluxDBTemplate(connectionFactory, new PointConverter()); } @Bean public DefaultInfluxDBTemplate defaultTemplate(final InfluxDBConnectionFactory connectionFactory) { return new DefaultInfluxDBTemplate(connectionFactory); } } 使用 @Autowired private InfluxDBTemplate influxDBTemplate; influxDBTemplate.createDatabase(); final Point p = Poinasurement("group") .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS) .tag("test", "default") .addField("used", 80L) .addField("free", 1L) .build(); influxDBTemplate.write(p); 基础操作 与传统数据库对比 influxdb中的名词传统数据库database数据库measurement数据库中的表points表中的一条数据 point

Point由时间戳(time)、数据(field)、标签(tags)组成

point属性传统数据库time每条数据的记录时间,是数据库的主要索引,会自动生成fields记录的值tags索引属性 数据库操作

显示数据库

show databases

创建数据库

create database testdatabase

删除数据库

drop database testdatabase

使用指定数据库

use testdatabase

显示所有表

SHOW MEASUREMENTS

新建表

insert test,hostname=server01 value=12345

test:表名 hostname:索引(tag) value:记录值(field)记录值可以有多个,系统自带追加时间戳

删除表

drop measurement test

查询数据

select * from 表名

插入数据

insert test,hostname=server02 value=6789

删除数据

create retention policy "rp_name" on "testdatabse" duration 3w replication 1 default

influxDB是没有提供直接删除数据记录的方法,但是提供数据保存策略,主要用于指定数据保留时间,超过指定时间,就删除这部分数据

数据库过期策略至少一个小时

数据保护策略

influxDB是没有提供直接删除数据记录的方法,但是提供数据保存策略,主要用于指定数据保留时间,超过指定时间,就删除这部分数据。

查看当前数据库保护策略

show retention policies on "testdatabase"

创建新的保护策略

create retention policy "rp_name" on "testdatabase" duration 3w replication 1 default

rp_name:策略名; db_name:具体的数据库名; 3w:保存3周,3周之前的数据将被删除,influxdb具有各种事件参数,比如:h(小时),d(天),w(星期); replication 1:副本个数,一般为1就可以了; default:设置为默认策略

修改保护策略

alter retention policy “rp_name” on “testdatabase” duration 30d default

删除保护策略

rop retention policy “rp_name” on “testdatabase" 服务操作

启动

sudo service influxdb start

重启

sudo service influxdb restart


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3