OpenTSDB部署与使用
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
OpenTSDB 是基于 HBase 存儲時間序列數(shù)據(jù)的一個開源數(shù)據(jù)庫,對于存儲監(jiān)控系統(tǒng)采集的數(shù)據(jù)來說非常合適,不僅在寫入查詢上有很高的效率,而且節(jié)省存儲空間。
?
安裝 HBase
因為 OpenTSDB 的后端存儲使用的是 HBase,所以我們需要先安裝 HBase。
參考文檔:?Quick Start - Standalone HBase
這里簡單搭建了一個單機的 HBase 環(huán)境:
conf/hbase-site.xml?的配置示例如下
<configuration><property><name>hbase.rootdir</name><value>file:///home/testuser/hbase</value></property><property><name>hbase.zookeeper.property.dataDir</name><value>/home/testuser/zookeeper</value></property> </configuration>通過命令行操作 HBase
這里可以稍微熟悉一下 HBase 的操作,非必須。
連接到 HBase
./bin/hbase shell
創(chuàng)建一張表
create 'test', 'cf'
查看表信息
list 'test'
向表中插入數(shù)據(jù)
put 'test', 'row1', 'cf:a', 'value1' put 'test', 'row2', 'cf:b', 'value2' put 'test', 'row3', 'cf:c', 'value3'查看表中所有數(shù)據(jù)
scan 'test'
查看指定行的數(shù)據(jù)
get 'test', 'row1'
禁用指定表(刪除表或修改表設置前需要先禁用該表)
disable 'test'
恢復指定表
enable 'test'
刪除表
drop 'test'
安裝OpenTSDB
參考文章
http://debugo.com/opentsdb/
http://opentsdb.net/docs/build/html/installation.html#runtime-requirements
直接從 github 上下載 OpenTSDB 的?release?版本的 RPM 包。安裝?yum?localinstall?opentsdb-2.2.0.noarch.rpm。
配置完成后,我們通過下面命令在 HBase 中建立 opentsdb 所需的表。默認情況下 opentsdb 建立的 HBase 表啟用了 lzo 壓縮。需要開啟 Hadoop 中的 lzo 壓縮支持, 這里我們直接在下面腳本中把 COMPRESSION 的支持關閉。修改?/usr/share/opentsdb/tools/create_table.sh,設置?COMPRESSION=NONE,并且在文件開始處設置 HBase 所在目錄,?HBASE_HOME=/home/xxx/hbase-1.1.3。之后執(zhí)行該腳本,在 HBase 中創(chuàng)建相應的表。
修改 OpenTSDB 的配置文件,/etc/opentsdb/opentsdb.conf,例如綁定的端口號等。這里需要注意的是?tsd.core.auto_create_metrics 從 false 改為 true。這樣上傳數(shù)據(jù)時會自動創(chuàng)建 metric,否則會提示 Unknown?metric 的錯誤。也可以設置為 false,但是使用?tsdb mkmetric proc.loadavg.1m?來手動添加 metric。
啟動 OpenTSDB,service opentsdb start?或者?nohup tsdb tsd &。
通過瀏覽器訪問?http://x.x.x.x:4242?查看是否安裝成功。
HTTP API
插入數(shù)據(jù)
/api/put
根據(jù) url 參數(shù)的不同,可以選擇是否獲取詳細的信息。
/api/put?summary?? ? ? ?// 返回失敗和成功的個數(shù)
{"failed": 0,"success": 1 }/api/put?details?? ? ? ?// 返回詳細信息
{"errors": [],"failed": 0,"success": 1 }通過POST方式插入數(shù)據(jù),JSON格式,例如
{"metric":"self.test", "timestamp":1456123787, "value":20, "tags":{"host":"web1"} }查詢數(shù)據(jù)
/api/query
可以選擇 Get 或者 Post 兩種方式,推薦使用 Post 方式,JSON 格式。
{"start": 1456123705,"end": 1456124985,"queries": [{"aggregator": "sum","metric": "self.test","tags": {"host": "web1"}},{"aggregator": "sum","metric": "self.test","tags": {"host": "web2"}}] }start 和 end 為指定的查詢時間段。
queries 為一個數(shù)組,可以指定多個查詢。
metric 和 tags 是用于過濾的查詢條件。
返回字符串也為json格式
[{"metric": "self.test","tags": {},"aggregateTags": ["host"],"dps": {"1456123785": 10,"1456123786": 10}},{"metric": "self.test","tags": {"host": "web1"},"aggregateTags": [],"dps": {"1456123784": 10,"1456123786": 15}} ]聚合
aggregator?是用于對查詢結果進行聚合,將同一 unix 時間戳內的數(shù)據(jù)進行聚合計算后返回結果,例如如果 tags 不填,1456123705 有兩條數(shù)據(jù),一條?host=web1,另外一條?host=web2,值都為10,那么返回的該時間點的值為 sum 后的 20。
條件過濾
可以針對 tag 進行一些條件的過濾,返回 tag 中 host 的值以 web 開頭的數(shù)據(jù)。
"queries": [{"aggregator": "sum","metric": "self.test","filters": [{"type": "wildcard","tagk": "host","filter": "web*"}]} ]downsample
簡單來說就是對指定時間段內的數(shù)據(jù)進行聚合后返回,例如需要返回每分鐘的平均值數(shù)據(jù)
"queries": [{"aggregator": "sum","metric": "self.test","downsample": "1m-avg","tags": {"host": "web1"}} ]作者:fatedier?
轉載于:https://my.oschina.net/weiweiblog/blog/1587064
總結
以上是生活随笔為你收集整理的OpenTSDB部署与使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 14.ZooKeeper Java AP
- 下一篇: 【grunt整合版】30分钟学会使用gr