安装
apt install influxdb influxdb-client
<ip>:8083
<ip>:8086
复制代码
influxDB中独有的一些概念
Point由时间戳(time)、数据(field)和标签(tags)组成
time: 每条数据记录的时间,也是数据库自动生成的主索引
fields:各种记录的值
tags: 各种有索引的属性
series: 所有数据,都需要通过图表来表示,表示这个表的数据在图标上画成几条线
复制代码
test,host=127.0.0.1,monitor_name=test count=1
test: 表名
host=127.0.0.1,monitor_name=test: tag
count=1: field
复制代码
$ influx
create database 'db_name'
show databases
use db_name
show measurement
复制代码
会自动创建表,插入数据
insert table_name,host=127.0.0.1,monitor_name=test count=1
drop measurement "table_name"
复制代码
通过http接口 插入数据
curl -i -XPOST 'http://10.0.0.10:8086/write?db=test' --data-binary 'test,host=127.0.0.1,monitor_name=test count=1'
复制代码
通过http接口 查询数据
curl -G 'http://10.0.0.10:8086/query?pretty=true' --data-urlencode "db=test" --data-urlencode "q=select * from test"
复制代码
数据保存策略(Retention Policies)
show retention policies on "db_name"
create retention policy "rp_name" on "db_name" duration 3w replication 1 default
alter retention policy "rp_name" on "db_name" duration 30d default
drop retention policy "rp_name"
复制代码
rp_name:策略名
db_name:具体的数据库名
3w:保存3周,3周之前的数据将被删除,influxdb具有各种事件参数,比如:h(小时),d(天),w(星期)
replication 1:副本个数,一般为1就可以了
default:设置为默认策略
复制代码
连续查询(Continous Queries)
联系查询,可以做数据统计采样 (数据超过周期不会被删除)
show continuous queries
create continous query cq_name on db_name begin select sum(count) into new_table_name from table_name group by time(30m) end
drop continous query cp_name on db_name
cq_name:连续查询名字
db_name:数据库名字
sum(count):计算总和
table_name:当前表名
new_table_name:存新的数据的表名
30m:时间间隔为30分钟
复制代码
用户管理
show users
create user "username" with password 'password'
create user "username" with password 'password' with all privileges
drop user "username"
复制代码