介绍
InfluxDB™ is a time series database designed to handle high write and query loads. It is an integral component of the TICK stack. InfluxDB is meant to be used as a backing store for any use case involving large amounts of timestamped data, including DevOps monitoring, application metrics, IoT sensor data, and real-time analytics.
基本概念
DataBase
类似于传统数据库中的 DataBase 概念
Measurement
和 OLAP 中广义上的度量概念一致,某些 OLAP 数据库中又称为 metric
Tag
和 OLAP 中广义上的维度概念一致,某些 OLAP 数据库中又称为 tagKV
Field
数值
Timestamp
时间戳
Points
数据点
Series
数据点组成的序列
Retention Policy
数据过期策略,即 TTL
环境部署
目前,因为 InfluxDB 2.x 还没有稳定版本发布,所以这里我们使用的 InfluxDB 版本是 1.7.x
编译
$ go get github.com/influxdata/influxdb
$ cd $GOPATH/src/github.com/influxdata/influxdb
$ go clean ./...
$ go install -ldflags="-X main.version=1.7.10" ./...
$ ll $GOPATH/bin
复制
启动
$ $GOPATH/bin/influxd
复制
Grafana
# 安装
$ wget https://dl.grafana.com/oss/release/grafana-6.0.0-beta2.x86_64.rpm
$ sudo yum localinstall grafana-6.0.0-beta2.x86_64.rpm
# 启动
$ systemctl daemon-reload
$ systemctl start grafana-server
$ systemctl status grafana-server
# 自启动
$ sudo systemctl enable grafana-server.service
复制
Telegraf
$ wget https://dl.influxdata.com/telegraf/releases/telegraf-1.12.3-1.x86_64.rpm
$ sudo yum localinstall telegraf-1.12.3-1.x86_64.rpm
$ telegraf config > telegraf.conf
$ telegraf --config telegraf.conf
复制
基本操作
版本
$ curl -sL -I localhost:8086/ping | grep -i version
复制
X-Influxdb-Version: v1.7.10
复制
控制台
# 输入如下命令,即可进入到 InfluxDB 命令交互的控制台
$ influx -host 'localhost' -port '8086'
复制
建表
> show databases;
复制
name: databases
name
----
_internal
复制
# CREATE DATABASE <database_name> [WITH [DURATION <duration>] [REPLICATION <n>] [SHARD DURATION <duration>] [NAME <retention-policy-name>]]
> create database "yuzhouwan";
复制
> show databases;
复制
name: databases
name
----
_internal
yuzhouwan
复制
> use yuzhouwan;
复制
Using database yuzhouwan
复制
写入
> insert blog,protocol=https,name=yuzhouwan value=666
复制
查询
明细查询
> select * from blog
复制
name: blog
time name protocol value
---- ---- -------- -----
1556438552229094000 yuzhouwan https 666
复制
聚合查询
> select mean(value) from blog
复制
name: blog
time mean
---- ----
0 666
复制
范围查询
> select * from blog WHERE time > '2019-04-01T00:00:00Z' OR time < '2019-05-01T00:00:00Z'
复制
name: blog
time name protocol value
---- ---- -------- -----
1556438552229094000 yuzhouwan https 666
复制
数据导出
方法 | 优缺点 |
---|---|
通过 HTTP 接口直接查询 | 简单易用 |
influx_tools 命令行工具里的 exporter 功能 | 并不能导出原始数据点,只能操作 shard |
influx_inspect 命令行工具里的 export 功能 | 支持导出原始数据点,直接操作底层 TSM、WAL 文件 |
query 接口
$ curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=yuzhouwan" --data-urlencode 'q=select * from blog'
复制
{
"results": [
{
"series": [
{
"columns": [
"time",
"name",
"protocol",
"value"
],
"name": "blog",
"values": [
[
"2019-04-28T08:02:32.229094Z",
"yuzhouwan",
"https",
666
]
]
}
],
"statement_id": 0
}
]
}
复制
influx_inspect 命令
$ influx_inspect export -database yuzhouwan -start 2019-01-01T00:00:00+00:00 -end 2019-12-01T00:00:00+00:00 -out yuzhouwan.out
复制
writing out tsm file data for yuzhouwan/autogen...complete.
复制
$ cat yuzhouwan.out
复制
# INFLUXDB EXPORT: 2019-01-01T08:00:00+08:00 - 2019-12-01T08:00:00+08:00
# DDL
CREATE DATABASE yuzhouwan WITH NAME autogen
# DML
# CONTEXT-DATABASE:yuzhouwan
# CONTEXT-RETENTION-POLICY:autogen
# writing tsm data
blog,name=yuzhouwan,protocol=https value=666 1556438552229094000
复制
评论
