端口信息
端口
8083 Web admin
8086 http api
8088 集群端口
概念
database 数据库
measurement 表
points 表中的一行数据
points 由time、field、tags组成
time 时间戳,数据库中的主索引,会自动生成
field 列(字段)
tags 相比field有索引
series 数据集合
retention policy(RP) 保留策略
points 格式
1 | <measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp] |
基本命令
influx 默认连接的本地8086端口
1 | influx -precision rfc3339 |
查看有哪些数据库
1 | SHOW DATABASES |
_internal
是安装InfluxDB时自动创建的数据库,用来存储一些运行时的指标数据
创建数据库
1 | CREATE DATABASE mydb |
切换数据库
1 | USE mydb |
插入数据
1 | INSERT cpu,host=serverA,region=us_west value=0.64 |
查看有哪些表(MEASUREMENTS)
1 | SHOW MEASUREMENTS |
查询
1 | SELECT * FROM cpu LIMIT 1 |
1 | SHOW SERIES FROM cpu |
查询schema相关
1 | SHOW DATABASES |
数据库管理相关
1 | CREATE DATABASE |
Retention Policy(RP) 保留策略相关
语法
1 | CREATE RETENTION POLICY <retention_policy_name> ON <database_name> DURATION <duration> REPLICATION <n> [SHARD DURATION <duration>] [DEFAULT] |
DURATION: 数据保存时间,最小1 hour,最大无限INF(infinite)
REPLICATION: 副本数量,单实例不起作用
示例
1 | CREATE RETENTION POLICY "one_day_only" ON "NOAA_water_database" DURATION 1d REPLICATION 1 |
Continuous queries(CQ) 连续查询相关
管理相关
1 | SHOW CONTINUOUS QUERIES |
alter
未提供,需先DROP再CREATE
基本语法
1 | CREATE CONTINUOUS QUERY <cq_name> ON <database_name> |
cq_query
要求1个函数、1个INTO语句、1个GROUP BY time()语句
1 | SELECT <function[s]> INTO <destination_measurement> FROM <measurement> [WHERE <stuff>] GROUP BY time(<interval>)[,<tag_key[s]>] |
示例
1 | CREATE CONTINUOUS QUERY "cq_basic" ON "transportation" |
高级语法 - 定时
1 | CREATE CONTINUOUS QUERY <cq_name> ON <database_name> |
示例,每30m执行一次
1 | CREATE CONTINUOUS QUERY "cq_advanced_every_for" ON "transportation" |
写入非默认RP需指定,例如
1 | INTO "one_day_only"."average_passengers" |
示例
1 | CREATE RETENTION POLICY 'one_day_only' ON mydb DURATION 1d REPLICATION 1 |
1 | CREATE CONTINUOUS QUERY "cq_advanced_every_for" ON "mydb" RESAMPLE EVERY 1h FOR 90m BEGIN SELECT mean("value") INTO "one_day_only"."average_cpu" FROM "cpu" GROUP BY time(30m) END |
权限
创建管理员
1 | CREATE USER admin WITH PASSWORD 'testtest' WITH ALL PRIVILEGES |
创建普通
1 | CREATE USER telegraf WITH PASSWORD 'testtest' |
授权
1 | GRANT ALL on telegraf TO telegraf |