opentsdb+grafana監控系按使用總結,opentsdbgrafana
一、OpenTSDB簡介開源監控系統OpenTSDB,用hbase儲存所有的時序(無須 採樣)來構建一個分布式、可伸縮的時間序列資料庫。它支援秒級資料擷取所有metrics,支援永久儲存,可以做容量規劃,並很容易的接入到現有的警示系 統裡。OpenTSDB可以從大規模的叢集(包括叢集中的網路裝置、作業系統、應用程式)中擷取相應的metrics並進行儲存、索引以及服務,從而使得這些資料更容易讓人理解,如web化,圖形化等。對於營運工程師而言,OpenTSDB可以擷取基礎設施和服務的即時狀態資訊,展示叢集的各種軟硬體錯誤,效能變化以及效能瓶頸。對於管理者而言,OpenTSDB可以衡量系統的SLA,理解複雜系統間的相互作用,展示資源消耗情況。叢集的整體 作業情況,可以用以輔助預算和叢集資源協調。對於開發人員而言,OpenTSDB可以展示叢集的主要效能瓶頸,經常出現的錯誤,從而可以著力重點解決重要問題。這裡有幾篇文字對於OpenTSDB的介紹非常詳細:http://liubin.org/blog/2016/03/05/tsdb-opentsdb/http://www.jianshu.com/p/0bafd0168647https://yq.aliyun.com/articles/54785 這個是對錶結構的詳細介紹https://zhengheng.me/2016/03/07/opentsdb-hbase-tuning/ 最佳化 二、OpenTSDB的安裝配置1、基本環境搭建首先確保你的系統有以下條件滿足: jdk 1.6 以上 並配置好環境變數 hbase 0.92 或更高版本 gnuplot 4.2 或更高(yum安裝吧) autotools(好像只需要其中的autoconf和automake即可)
#1. 重新安裝新版本autoconf/automake#刪除舊版本yum erase autoconf#安裝新版本autoconfwget http://mirrors.ustc.edu.cn/gnu/autoconf/autoconf-2.68.tar.gztar -zxvf autoconf-2.68.tar.gzcd autoconf-2.68./configuremakemake installln -s /usr/local/bin/autoconf /usr/bin/autoconf#安裝新版本automakewget http://mirrors.ustc.edu.cn/gnu/automake/automake-1.11.2.tar.gztar -zxvf automake-1.11.2.tar.gzcd automake-1.11.2./configuremakemake installln -s /usr/local/bin/automake /usr/bin/automakeln -s /usr/local/bin/aclocal /usr/bin/aclocal#2.安裝gnuplot-4.4.0wget http://nchc.dl.sourceforge.net/project/gnuplot/gnuplot/4.4.0/gnuplot-4.4.0.tar.gztar -zxvf gnuplot-4.4.0.tar.gzcd gnuplot-4.4.0./configuremakemake installln -s /usr/local/bin/gnuplot /usr/bin/gnuplot
2、OpenTSDB的安裝然後下面是我通過源碼安裝的過程,希望能夠有借鑒意義:
1 git clone https://github.com/OpenTSDB/opentsdb.git2 cd opentsdb3 ./build.sh4 #當build.sh運行完畢的時候 你應該在opentsdb/build檔案夾下看到opentsdb.jar
最後安裝成功了,這裡總結一下:首先,java要安裝好,各變數也要配置好;其次,autotools的那幾個工具也要安裝好;opentsdb必須的gnuplot也要安裝好; 額外:因為OpenTSDB的後端是hbase,所以這裡也加上我配置的hbase的簡單介紹:1、hbase的安裝配置,解壓完後,在/etc/profile中加上 HBASE_HOME=path/to/hbase-0.94.X 不加的話,後面命令需要自己手動加上完成後source /etc/profile生效;然後,配置hbase的zookeeper屬性,這與 hbase-env.sh 檔案相關,檔案中 HBASE_MANAGES_ZK 環境變數用來設定是使用hbase預設內建的 Zookeeper還是使用獨立的ZooKeeper。HBASE_MANAGES_ZK=false 時使用獨立的,為true時使用預設內建的。手動啟動hbase:./start-hbasecd opentsdb的build目錄 && HBASE_HOME=/home/xxx/hbase-1.2.5 ./src/create_table.sh./tsdb tsd
3、設定檔
設定檔及參數:
zookeeper(hbase依賴於zookeeper所以保證有hbase的同時就保證了有zookeeper)
在opentsdb/src檔案夾下有一個opentsdb.conf的設定檔,內有3個主要屬性需要配置: tsd.http.cachedir opentsdb的快取資料存放目錄,找個路徑配置好 tsd.http.staticroot opentsdb web 靜態檔案的root路徑,一般在opentsdb/build/staticroot tsd.network.port 綁定的連接埠下面配置為常用可選配置 tsd.network.bind = 0.0.0.0 web 頁面綁定IP,一般配置為0.0.0.0 保證其他IP可以訪問opentsdb的web頁面。 tsd.storage.hbase.zk_quorum = localhost 這個為zookeeper的地址。一般單機版hbase不需要配置 預設在本機。如果zookeeper是獨立的或者分布式在其他機器上請指定IP 多個IP逗號分隔.還有一些其他配置,請參見官網文檔:http://opentsdb.net/docs/build/html/user_guide/configuration.html 設定檔填寫好了之後將其複製至/etc/下 啟動opentsdb會從以下幾個地方搜尋設定檔:./opentsdb.conf/etc/opentsdb.conf/etc/opentsdb/opentsdb.conf/opt/opentsdb/opentsdb.conf如果你多個地方都有設定檔,請確保這些多個設定檔的內容一致。也就是說修改一個要同步所有,不然根據你啟動命令執行的路徑不同可能會搜尋到不同的設定檔。建議只弄一個 放在/etc/下就好了。
注意!若要將opentsdb的tag_values()函數獲得的結果自動更新,需要設定四個參數在設定檔中
- tsd.core.meta.enable_realtime_uid
- tsd.core.meta.enable_tsuid_tracking
- tsd.core.meta.enable_tsuid_incrementing
- tsd.core.meta.enable_realtime_ts
opentsdb設定檔說明:http://opentsdb.net/docs/build/html/user_guide/stats.html
| 參數名 |
類型 |
是否必選 |
預設值 |
詳細介紹 |
| tsd.core.auto_create_metrics |
Boolean |
Optional |
false |
新metric的資料點是否被指定UID。 當為false時,資料庫中不具有metric的資料點將被拒絕並將拋出異常。 |
| tsd.core.auto_create_tagks (2.1) |
Boolean |
Optional |
true |
帶有新標籤名稱的資料點是否會將一個UID分配給tagk。 當為false時,具有不在資料庫中的標籤名稱的資料點將被拒絕並將拋出異常。 |
| tsd.core.auto_create_tagvs (2.1) |
Boolean |
Optional |
true |
是否具有新標籤值的資料點將分配給tagv的UID。 當為false時,具有不在資料庫中的標記值的資料點將被拒絕並將拋出異常。 |
4、啟動OPENTSDB:首先先建立hbase表:在opentsdb/src下有個create_tab.sh的指令碼執行:env COMPRESSION=NONE HBASE_HOME=path/to/hbase-0.94.X ./src/create_table.shCOMPRESSION=NONE指定hbase表的壓縮方式,可選:NONE, LZO, GZIP or SNAPPYHBASE_HOME不多說,如果配置好了在環境變數中可以不寫這個。最後一個就是執行建表指令碼了。建表完成後就可以啟動了:在opentsdb/build檔案夾下有個tsdb的指令碼 執行./tsdb tsd 即可啟動opentsdb 開啟對應ip和port的頁面即可看到頁面,如要後台執行:nohup ./tsdb tsd & 即可
5、OpenTSDB的簡單使用telnet用戶端發送資料至opentsdb建立metric:./tsdb mkmetric metricNametelnet ip port 串連到opentsd文法如下: put 如:put sys.cpu.user 1356998400 42.5 host=webserver01 cpu=0 post方式發送資料:發送post請求至 ip:port/api/put,參數為json資料,如下:
| Name |
Data Type |
Required |
Description |
QS |
| metric |
String |
Required |
The name of the metric you are storing |
sys.cpu.nice |
| timestamp |
Integer |
Required |
A Unix epoch style timestamp in seconds or milliseconds. The timestamp must not contain non-numeric characters. |
1365465600 |
| value |
Integer, Float, String |
Required |
The value to record for this data point. It may be quoted or not quoted and must conform to the OpenTSDB value rules: Writing Data |
42.5 |
| tags |
Map |
Required |
A map of tag name/tag value pairs. At least one pair must be supplied. |
{"host":"web01"} |
樣本:{ "metric": "sys.cpu.nice", "timestamp": 1346846400, "value": 18, "tags": { "host": "web01", "dc": "lga" }}發送成功會返回204狀態詳細請參見:http://opentsdb.net/docs/build/html/api_http/put.html-------------------------------------------scan命令掃描命令對於調試和匯出資料點很有用。 提供開始時間,可選的結束時間和一個或多個查詢,響應將是可接受用於匯入命令的文字格式設定的儲存或資料點的原始位元組資料。 掃描還提供刪除資料的基本方法。 scan命令接受常見的CLI參數。 資料被發送到標準輸出。請注意,雖然查詢需要彙總器,但卻被有效地忽略。 如果查詢包含許多時間序列,則掃描輸出可能非常大,因此在製作查詢時要小心。 scan [--delete|--import] START-DATE [END-DATE] query [queries...]
| Name |
Data Type |
Description |
Default |
Example |
| --delete |
Flag |
Optional flag that deletes data in any row that matches the query. See warning below. 可選標記,用於刪除與查詢匹配的任何行中的資料。 |
Not set |
--delete |
| --import |
flag |
Optional flag that outputs results in a text format useful for importing or storing as a backup. |
Not set |
--import |
| START-DATE |
String or Integer |
Starting time for the query. This may be an absolute or relative time. See Dates and Times for details |
|
1h-ago |
| END-DATE |
String or Integer |
Optional end time for the query. If not provided, the current time is used. This may be an absolute or relative time. See Dates and Times for details |
Current timestamp |
2014/01/01-00:00:00 |
| query |
String |
One or more command line queries |
|
sum tsd.hbase.rpcs type=put |
example ./tsdb scan 2014/05/01 sum test_uid ed=endp --delete./tsdb scan 2014/05/01 sum TcpExt.ArpFilter --delete 三、grafana安裝(grafana的具體介紹及使用方法會單獨開一篇文章介紹) Grafana 安裝1, 在官網下載grafana 安裝包,安裝好了之後,根據安裝輸出日誌的提示 啟動 grafana 即可(grafana-server start)2,啟動 grafana 後 開啟機器 IP:3000連接埠 即可登入 grafana 介面,初始密碼 admin admin3,在 datasource 中添加一個資料來源,選擇 opentsdb 填入 ip+連接埠 即可。opentsdb 預設為4242連接埠。