InfluxDB-重點概念

表結構


  1. database,和mysql一樣,表示數據庫。
  2. measurement,類似SQL數據表。和mysql數據表不同的是,不再需要我們自己建立數據表,在我們插入一個Point時,可以理解爲根據measurement建立一個數據表。
  3. ponint,相當於一行數據,point可以理解爲一個 時間點 的數據,因爲influxDb是基於時間序列的。
<measurement>[,<tag-key>=<tag-value>...] [,<field-key>=<field-value>...] [timestamp]

包括四個部分:

  • measurement,相當於mysql數據庫表名【必填項】。
  • tag-key,可以0~多個【選填項】。tag-value的類型必須都是String類型。
  • field-key,保存我們需要統計數據。1~多個【必填項】。field-value的類型可以是strings、floats、 integers 或者 booleans。
  • timestapmp,時間戳,是主鍵,默認當前時間 【選填項】。

比較tag和field


(1) 先說下feild

在一個二維座標系中,如果我們繪製一個曲線,需要一系列的點”(x=x1,y=y1),…,(x=xn,y=yn)”。在influxDb中,可以把x座標軸理解爲timestamp字段的值,凸顯了時間序列的概念。爲什麼可以多個<field-key,field-value>?這是因爲可能在一個座標系中可能需要繪製多條線。

(2) 再說下tag

tag作用就是爲了作爲索引來實現快速的查詢fied的數據。在influxDb中對於field是沒有索引的,如果根據field查詢數據時需要掃描數據,而tag是有索引的,根據tag作爲查詢條件查詢field時,速度會很快。

retention policy


備份數據的策略,主要包括數據保留時間和備份個數兩個信息。查詢licai-data數據庫上面的retension policy,如下

serires


它是由database、retension policy確定的一個measurement中所有tag的組合。查看series

> show series from gw_counter
key
---
gw_counter,host=192.168.10.25,url=gw_counter/camera/getbypage
gw_counter,host=192.168.10.25,url=gw_counter/face/recog/ext/binlog/getbypage
gw_counter,host=192.168.10.25,url=gw_counter/face/recog/ext/engine/add
gw_counter,host=192.168.10.25,url=gw_counter/face/recog/ext/engine/remove
gw_counter,host=192.168.10.25,url=gw_counter/face/recog/ext/group/getall/ext
gw_counter,host=192.168.10.25,url=gw_counter/face/tool/detect
gw_counter,host=192.168.10.25,url=gw_counter/group/compress/progress
gw_counter,host=192.168.10.25,url=gw_counter/group/getall
gw_counter,host=192.168.10.25,url=gw_counter/group/getallservers
gw_counter,host=192.168.10.25,url=gw_counter/group/modeling/progress/ext

關於唯一鍵


如何表示唯一Pont?可以由series和timestamp來唯一標識,或者說由database、retension policy、measurement、tagsets、timestamp來唯一標識,因爲series是由database、retension policy確定的一個measurement中所有tag的組合,所以等同於database、retension policy、measurement和tagsets。

對於一個database有多個retension policy,對於每一個retenison policy都是表的集合。所以當我們查詢一個表時,必須指定這個表所在的retension pliciy

select * from cpu  #如果不指定就取默認

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章