生活随笔
收集整理的這篇文章主要介紹了
influxdb Measurements
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
第一次看influxdb的代碼實(shí)例時(shí)不明白influxdb Measurements是什么意思。經(jīng)過研究總結(jié)一下。
1)measurement,相當(dāng)于關(guān)系數(shù)據(jù)庫中的table,包含tag,field,time,例如:select * from cpu_usage
2)field是必須的,并且不能根據(jù)field來排序
3)tag是可選的,tag可以用來做索引,tag是以字符串的形式存放的
4)InfluxDb可以隨意添加measurements, tags, fields, time
5)points相當(dāng)于表中的一條數(shù)據(jù)
6)InfluxDb的概念,Point由時(shí)間戳(time)、數(shù)據(jù)(field)、標(biāo)簽(tags)組成
time 每個(gè)數(shù)據(jù)記錄時(shí)間,是數(shù)據(jù)庫中的主索引(會自動生成)
fields 各種記錄值(沒有索引的屬性)也就是記錄的值:溫度, 濕度,每條記錄可以不同
tags 各種有索引的屬性:地區(qū),海拔
7)go操作Measurements代碼
package mainimport ("log""time""github.com/influxdata/influxdb/client/v2"
)const (MyDB = "nfdump"
//數(shù)據(jù)庫名username = "zhja"
//用戶名password = "zhjazhja"
//密碼
)func main(){//鏈接數(shù)據(jù)庫c, err := client.NewHTTPClient(client.
HTTPConfig{Addr: "http://192.168.210.130:8086",
Username: username,
Password: password,
})if err !=
nil {log.Fatalln("Error: ",
err)}// Create a new point batchbp, err := client.NewBatchPoints(client.
BatchPointsConfig{Database: MyDB,
Precision: "s",
})if err !=
nil {log.Fatalln("Error: ",
err)}// Create a point and add to batchtags := map[
string]
string{"cpu1": "cpu-total1"
}fields := map[
string]
interface{}{"idle1": 10.1,"system1": 53.3,"user1": 46.6,
}pt, err := client.NewPoint("cpu_usage", tags, fields,
time.
Now())if err !=
nil {log.Fatalln("Error: ",
err)}bp.
AddPoint(pt)// Write the batchc.
Write(bp)
} ?
轉(zhuǎn)載于:https://www.cnblogs.com/zhja/p/6065515.html
總結(jié)
以上是生活随笔為你收集整理的influxdb Measurements的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。