InfluxDB是什么

InfluxDB是什么

是什么

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

时序数据库是一种按照时间存储的数据库。解决是海量数据的高效插入查询。主要应用在互联网的大规模数据统计分析上面,物联网的信息收集方面。

特点
部署简单、使用方便,无需任何外部依赖即可独立部署
提供类似于SQL的查询语言
提供灵活的数据保存策略来设置数据的保留时间和副本数,在保障数据可靠性的同时,及时删除过期数据,释放存储空间
高性能读写及存储率
丰富的聚合函数,支持AVG、SUM、MAX、MIN等聚合函数。

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

使用
springboot集成influxdb

导包

<dependency>
  <groupId>com.github.miwurster</groupId>
  <artifactId>spring-data-influxdb</artifactId>
  <version>1.8</version>
</dependency>

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<Point> influxDBTemplate(final InfluxDBConnectionFactory connectionFactory)
  {
    return new InfluxDBTemplate<>(connectionFactory, new PointConverter());
  }
  
  @Bean
  public DefaultInfluxDBTemplate defaultTemplate(final InfluxDBConnectionFactory connectionFactory)
  {
    return new DefaultInfluxDBTemplate(connectionFactory);
  }
}

使用

@Autowired
private InfluxDBTemplate<Point> influxDBTemplate;


influxDBTemplate.createDatabase();
final Point p = Point.measurement("group")
  .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
  .tag("test", "default")
  .addField("used", 80L)
  .addField("free", 1L)
  .build();
influxDBTemplate.write(p);

基础操作
与传统数据库对比

在这里插入图片描述
point
Point由时间戳(time)、数据(field)、标签(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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

clarence.wei

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值