连接
直接通过influx登录,也可以通过如下命令进行远程登录。
influx -host xx.xx.xx.xx -port 8086
数据库操作
创建数据库:
create database db_metric
查看数据库:
> show databases
name: databases
name
----
_internal
db_metric
>
切换到当前数据库:
> use db_metric
Using database db_metric
数据表操作
查看所有表:
> show measurements
name: measurements
name
----
gw_counter
gw_cpu
gw_histogram
gw_memory
gw_meter
插入数据:
当measument相同时,如果插入多条时间搓一样的记录,则只会保留最新的值。
INSERT cpu,host=serverA,region=us_west value=0.98
查询记录:
(1) 查询一个表中所有数据
> select * from gw_counter
name: gw_counter
time count host url
---- ----- ---- ---
1544877694000000000 33139 192.168.10.25 gw_counter/face/tool/detect
1544877694000000000 22087 192.168.10.25 gw_counter192.168.10.25:7100/face/tool/detect
1544877694000000000 11052 192.168.10.25 gw_counter192.168.10.24:7100/face/tool/detect
1544877704000000000 24525 192.168.10.25 gw_counter192.168.10.25:7100/face/tool/detect
1544877704000000000 12269 192.168.10.25 gw_counter192.168.10.24:7100/face/tool/detect
(2) 查看数据库中所有记录,通过”/.*/”表示所有的表
select * from /.*/
(3) 根据tag-key查询,查询数据时,都是按照tag-key进行查询,因为tag-key是存在索引的。
select * from cpu where host='serverA'
(4) 根据field-key进行查询
select * from cpu where value=0.98
删除表:
DROP MEASUREMENT <measurement_name>
分页查询limit操作:
limit pageSize offset
> select * from gw_counter limit 5 offset 1
name: gw_counter
time count host url
---- ----- ---- ---
1544877694000000000 22087 192.168.10.25 gw_counter192.168.10.25:7100/face/tool/detect
1544877694000000000 11052 192.168.10.25 gw_counter192.168.10.24:7100/face/tool/detect
1544877704000000000 24525 192.168.10.25 gw_counter192.168.10.25:7100/face/tool/detect
1544877704000000000 12269 192.168.10.25 gw_counter192.168.10.24:7100/face/tool/detect
1544877704000000000 36794 192.168.10.25 gw_counter/face/tool/detect