連接
直接通過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