您好,登錄后才能下訂單哦!
01-InfluxDB入門介紹
02-influxdb的權(quán)限管理
influxdb是使用GO編寫的基于時間序列的數(shù)據(jù)庫,用于存儲大量帶有時間戳的數(shù)據(jù),報(bào)錯DevOps監(jiān)控,日志數(shù)據(jù),應(yīng)用程序的指標(biāo)、數(shù)據(jù)分析數(shù)據(jù)等等。通過influxdb自動保存數(shù)據(jù),你不需要刪除和清理,只需要定義一段時間DB會幫你自動清理。
特點(diǎn)
其它信息
influxdb默認(rèn)端口8086,默認(rèn)是http協(xié)議接口,使用起來簡單方便
下載安裝包:wget 'http://dl.influxdata.com/influxdb/nightlies/influxdb-nightly_darwin_amd64.tar.gz'
解壓安裝包:tar zxf influxdb-nightly_darwin_amd64.tar.gz
啟動influxdb:cd influxdb-1.7.0~n201811230800-0/ && ./usr/bin/influxd
登錄數(shù)據(jù)庫:./usr/bin/influx
查看幫助:
> help
Usage:
connect <host:port> connects to another node specified by host:port
auth prompts for username and password
pretty toggles pretty print for the json format
chunked turns on chunked responses from server
chunk size <size> sets the size of the chunked responses. Set to 0 to reset to the default chunked size
use <db_name> sets current database
format <format> specifies the format of the server responses: json, csv, or column
precision <format> specifies the format of the timestamp: rfc3339, h, m, s, ms, u or ns
consistency <level> sets write consistency level: any, one, quorum, or all
history displays command history
settings outputs the current settings for the shell
clear clears settings such as database or retention policy. run 'clear' for help
exit/quit/ctrl+d quits the influx shell
show databases show database names
show series show series information
show measurements show measurement information
show tag keys show tag key information
show field keys show field key information
A full list of influxql commands can be found at:
https://docs.influxdata.com/influxdb/latest/query_language/spec/
登錄Influxdb
influx -precision rfc3339
-precision rfc3339 #精準(zhǔn)的指定參數(shù),rfc3339時間格式
現(xiàn)在influxdb已經(jīng)搭建完成,可以進(jìn)行入門操作,建庫、建表寫數(shù)據(jù)。當(dāng)寫入一個時間序列數(shù)據(jù)時候他可能包含0到多個點(diǎn),每個數(shù)據(jù)都對應(yīng)一個監(jiān)控樣本(例如cpu_load、溫度)至少包括一個鍵值對(cplu_load=5);
在這里可以認(rèn)為:
tags是表中索引
在這里和mysql不同是,你可以有幾百萬個measurements,而且n不需要提前定義表結(jié)構(gòu)、也不會存儲空值;
1.創(chuàng)建一個數(shù)據(jù)庫
CREATE DATABASE {NAME};
> create database order_record;
> show databases;
name: databases
name
----
_internal
order_record
這時候我們發(fā)現(xiàn)數(shù)據(jù)庫有一個表“_internal”,其實(shí)這個表是influxdb數(shù)據(jù)庫的一些指標(biāo)存儲庫。有點(diǎn)類似mysql數(shù)據(jù)庫的mysql庫。
2.寫數(shù)據(jù)
注意在寫數(shù)據(jù)的時候如果不添加時間戳,系統(tǒng)會默認(rèn)添加一個時間
<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp]
> use order_record;
Using database order_record
> INSERT cpu,host=serverA,region=us_west value=0.64
> SELECT "host", "region", "value" FROM "cpu"
name: cpu
time host region value
---- ---- ------ -----
2018-11-23T16:01:29.995044Z serverA us_west 0.64
3.數(shù)據(jù)讀
同mysql一樣如果你想空值內(nèi)容輸出行數(shù),可以用 [limit 1~n;],同樣influxdb的sql也支持go語言格式的正則。
> select * from cpu;
name: cpu
time host region value
---- ---- ------ -----
2018-11-23T16:01:29.995044Z serverA us_west 0.64
> INSERT stock,symbol=AAPL bid=127.46,ask=127.48
> INSERT temperature,machine=unit42,type=assembly external=25,internal=37 1434067467000000000
> SELECT "host", "region", "value" FROM "cpu"
name: cpu
time host region value
---- ---- ------ -----
2018-11-23T16:01:29.995044Z serverA us_west 0.64
每個表輸出一行
SELECT * FROM /.*/ LIMIT 1
4.查看當(dāng)前數(shù)據(jù)庫的分片
> SHOW SHARDS
name: _internal
id database retention_policy shard_group start_time end_time expiry_time owners
-- -------- ---------------- ----------- ---------- -------- ----------- ------
1 _internal monitor 1 2018-11-24T00:00:00Z 2018-11-25T00:00:00Z 2018-12-02T00:00:00Z
name: zabbix
id database retention_policy shard_group start_time end_time expiry_time owners
-- -------- ---------------- ----------- ---------- -------- ----------- ------
5 zabbix autogen 5 1969-12-29T00:00:00Z 1970-01-05T00:00:00Z 1970-01-05T00:00:00Z
4 zabbix autogen 4 1970-01-12T00:00:00Z 1970-01-19T00:00:00Z 1970-01-19T00:00:00Z
3 zabbix autogen 3 2018-11-19T00:00:00Z 2018-11-26T00:00:00Z 2018-11-26T00:00:00Z
0.接口介紹
接口路徑 | 描述 |
---|---|
/debug/pprof | debug排查問題使用 |
/debug/requests | 使用這個請求監(jiān)聽最近是否有請求 |
/debug/vars | 查詢influxdb收集到靜態(tài)信息 |
/ping | 檢測influxdb狀態(tài) |
/query | 查詢數(shù)據(jù)接口(同時可以創(chuàng)建ku) |
/write | 寫入數(shù)據(jù)接口(一個已存在數(shù)據(jù)庫) |
狀態(tài)碼介紹:
1.創(chuàng)建數(shù)據(jù)庫
curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb"
HTTP/1.1 200 OK
Content-Type: application/json
Request-Id: 5edd88a8-ef90-11e8-83cd-a0999b0f94e3
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.7.0~n201811230800
X-Request-Id: 5edd88a8-ef90-11e8-83cd-a0999b0f94e3
Date: Sat, 24 Nov 2018 02:26:38 GMT
Transfer-Encoding: chunked
{"results":[{"statement_id":0}]}
2.寫入數(shù)據(jù)
curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.65 1434055564000000000'
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 1ae386c4-ef91-11e8-83d8-a0999b0f94e3
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.7.0~n201811230800
X-Request-Id: 1ae386c4-ef91-11e8-83d8-a0999b0f94e3
Date: Sat, 24 Nov 2018 02:31:53 GMT
3.寫入多個數(shù)據(jù)點(diǎn)
curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server02 value=0.67
cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257
cpu_load_short,direction=in,host=server01,region=us-west value=2.0 1422568543702900257'
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 574f52a0-ef91-11e8-83d9-a0999b0f94e3
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.7.0~n201811230800
X-Request-Id: 574f52a0-ef91-11e8-83d9-a0999b0f94e3
Date: Sat, 24 Nov 2018 02:33:34 GMT
4.從文件導(dǎo)入數(shù)據(jù)庫
從文件導(dǎo)入時候建議不要超過5000條,如果超過請對文件進(jìn)行切割,因?yàn)閔ttp api的接口5s會超時,請求數(shù)據(jù)過多會導(dǎo)致數(shù)據(jù)無法確認(rèn)是否成功。
文件cpu_data.txt內(nèi)容如下:
cpu_load_short,host=server02 value=111
cpu_load_short,host=server02,region=us-west value=0.222 1543027130702900257
cpu_load_short,direction=in,host=server01,region=us-west value=111.222 1543027129702900257
curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary @cpu_data.txt
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 4b2ed710-ef92-11e8-83e3-a0999b0f94e3
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.7.0~n201811230800
X-Request-Id: 4b2ed710-ef92-11e8-83e3-a0999b0f94e3
Date: Sat, 24 Nov 2018 02:40:24 GMT
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。