欢迎光临
我们一直在努力

InfluxDB学习之InfluxDB的基本操作

InfluxDB 是一个开源分布式时序、事件和指标数据库。

使用 Go 语言编写,无需外部依赖。其设计目标是实现分布式和水平伸缩扩展。

它有三大特性:

1. Time Series (时间序列):你可以使用与时间有关的相关函数(如最大,最小,求和等)

2. Metrics(度量):你可以实时对大量数据进行计算

3. Eevents(事件):它支持任意的事件数据

特点

schemaless(无结构),可以是任意数量的列

Scalable

min, max, sum, count, mean, median 一系列函数,方便统计

Native HTTP API, 内置http支持,使用http读写

Powerful Query Language 类似sql

Built-in Explorer 自带管理工具

安装好influxdb后通过终端登录到数据库,http api over 8086,页面为8083

[root@mycat ~]# inf

influx          influx_inspect  influx_tsm      infocmp         infotocap

influxd         influx_stress   info            infokey     

通过influx登陆终端

[root@mycat ~]# influx

Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.

Connected to http://localhost:8086 version 0.13.0

InfluxDB shell version: 0.13.0

1、Creating a database,注意关键词的大小写

> CREATE DATABASE mydb;

> SHOW DATABASES;

name: databases

—————

name

telegraf

_internal

mytab

mydb

2、切换库,有的关键字也没那么规范

> use mydb

Using database mydb

> USE mydb

Using database mydb

3、Writing and exploring data,写入一条数据需要基础格式

1、a short primer on the datastore#存放数据的实体对象,相当在关系型数据的表名

数据在时序数据库(influxDB)是有组织的时间序列,包含一个 测量值(即在RMDB中的字段),在INFLUXDB中如cpu_load或者temperature,

Points are written to InfluxDB using the Line Protocol, which follows the following format:

<measurement>[,<tag-key>=<tag-value>…] <field-key>=<field-value>[,<field2-key>=<field2-value>…] [unix-nano-timestamp]

The following lines are all examples of points that can be written to InfluxDB:

cpu,host=serverA,region=us_west value=0.64

payment,device=mobile,product=Notepad,method=credit billed=33,licenses=3i 1434067467100293230

stock,symbol=AAPL bid=127.46,ask=127.48

temperature,machine=unit42,type=assembly external=25,internal=37 1434067467000000000

这3条例子具体写法:

InfluxDB中没有显式的新建表的语句,只能通过insert数据的方式来建立新表。如下所示:

insert disk_free,hostname=server01 value=442221834240i 1435362189575692182

其中 disk_free 就是表名,hostname是索引,value=xx是记录值,记录值可以有多个,最后是指定的时间

> insert cpu,host=serverA,region=us_west value=0.64

> select host,region ,value from cpu ##官方写法是把这些测量值加引号

name: cpu

———

timehostregionvalue

1481203149917071248serverAus_west0.64

insert disk_free,hostname=server01 value=442221834240i 1435362189575692182

在这条语句中,disk_free是表名,hostname=server01是tag,属于索引,value=xx是field,这个可以随意写,随意定义。

A point with the measurement name of cpu and tags host and region has now been written to the database, with the measured value of 0.64.

另一种类型的数据存储,在相同的测量两个字段:

相同的测量值包含两个字段类型的数据

INSERT temperature,machine=unit42,type=assembly external=25,internal=37

> select * from temperature

name: temperature

—————–

timeexternalinternalmachinetype

14812037975306309012537unit42assembly

删除一个度量值

delete from cpu

show 支持的方法

 CONTINUOUS, DATABASES, DIAGNOSTICS, FIELD, GRANTS, MEASUREMENTS, QUERIES, 

RETENTION, SERIES, SHARD, SHARDS, STATS, SUBSCRIPTIONS, TAG, USERS

SHOW TAG KEYS FROM “temperature” 显示度量值的标签===show create table aa

influxdb支持正则

series操作

series表示这个表里面的数据,可以在图表上画成几条线,series主要通过tags排列组合算出来

show series from mem

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。