時序數據庫
-
時序數據庫全稱為時間序列數據庫。主要用於處理帶時間標簽(按照時間的順序變化,即時間序列化)的數據,帶時間標簽的數據也稱為時間序列數據。時間序列數據主要由電力行業、化工行業、物聯網行業等各類型實時監測、檢查與分析設備所采集、產生的數據,這些數據的典型特點是:產生頻率快(每一個監測點一秒鍾內可產生多條數據)、嚴重依賴於采集時間(每一條數據均要求對應唯一的時間)、測點多信息量大(常規的實時監測系統均有成千上萬的監測點,監測點每秒鍾都產生數據,每天產生幾十GB的數據量)。
-
時序數據庫最新排名(DB-Engines):
OpenTSDB介紹
-
OpenTSDB用HBase存儲所有的時序來構建一個分布式、可伸縮的時間序列數據庫。它支持秒級數據采集所有metrics,支持永久存儲,可以做容量規划,並很容易的接入到現有的報警系統里。OpenTSDB可以從大規模的集群(包括集群中的網絡設備、操作系統、應用程序)中獲取相應的metrics並進行存儲、索引以及服務,從而使得這些數據更容易讓人理解,如web化、圖形化等。
-
底層使用Hbase作為其分布式存儲引擎,采用的也是LSM tree。
安裝
- 安裝依賴
jdk
hbase
- Opentsdb依賴Gnuplot,它 是一個命令行的交互式繪圖工具。用戶通過輸入命令,可以逐步設置或修改繪圖環境,並以圖形描述數據或函數,使我們可以借由圖形做更進一步的分析。
yum install gnuplot
- 下載源碼包:
wget https://github.com/OpenTSDB/opentsdb/releases/download/v2.3.0/opentsdb-2.3.0.tar.gz
- 解壓:
tar zxvf opentsdb-2.3.0.tar.gz
- 進目錄
cd opentsdb-2.3.0
- 編譯安裝
./build.sh
cd build
make install
配置OpenTSDB
# vim ./opentsdb.conf
# The TCP port TSD should use for communications
# *** REQUIRED ***
tsd.network.port = 4242
# The location of static files for the HTTP GUI interface.
# *** REQUIRED ***
tsd.http.staticroot =build/staticroot
# Where TSD should write it's cache files to
# *** REQUIRED ***
tsd.http.cachedir = /tmp/tsd
# Whether or not to automatically create UIDs for new metric types, default is False
tsd.core.auto_create_metrics = true
# A comma separated list of Zookeeper hosts to connect to
tsd.storage.hbase.zk_quorum = cdhmanager:2181
# Cover duplicates data
tsd.storage.fix_duplicates = true
配置參數優先級:命令行參數 > 配置文件 > 默認值
你可以在命令行中通過--config指定配置文件所在路徑,如果沒有指定,OpenTSDB會從以下路徑尋找配置文件:
- ./opentsdb.conf
- /etc/opentsdb.conf
- /etc/opentsdb/opentsdb.conf
- /opt/opentsdb/opentsdb.conf
protected void loadConfig() throws IOException {
if (config_location != null && !config_location.isEmpty()) {
loadConfig(config_location);
return;
}
final ArrayList<String> file_locations = new ArrayList<String>();
// search locally first
file_locations.add("opentsdb.conf");
// add default locations based on OS
if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) {
file_locations.add("C:\\Program Files\\opentsdb\\opentsdb.conf");
file_locations.add("C:\\Program Files (x86)\\opentsdb\\opentsdb.conf");
} else {
file_locations.add("/etc/opentsdb.conf");
file_locations.add("/etc/opentsdb/opentsdb.conf");
file_locations.add("/opt/opentsdb/opentsdb.conf");
}
for (String file : file_locations) {
try {
FileInputStream file_stream = new FileInputStream(file);
Properties props = new Properties();
props.load(file_stream);
// load the hash map
loadHashMap(props);
} catch (Exception e) {
// don't do anything, the file may be missing and that's fine
LOG.debug("Unable to find or load " + file, e);
continue;
}
// no exceptions thrown, so save the valid path and exit
LOG.info("Successfully loaded configuration file: " + file);
config_location = file;
return;
}
LOG.info("No configuration found, will use defaults");
}
創建表
env COMPRESSION=NONE HBASE_HOME=/usr ./src/create_table.sh
-
COMPRESSION=NONE,不使用壓縮。如使用則需修改hadoop配置。
-
腳本會在hbase中自動創建tsdb所用到的表
create 'tsdb-uid',
{NAME => 'id', COMPRESSION => 'NONE', BLOOMFILTER => 'ROW'},
{NAME => 'name', COMPRESSION => 'NONE', BLOOMFILTER => 'ROW'}
0 row(s) in 3.3470 seconds
Hbase::Table - tsdb-uid
create 'tsdb',
{NAME => 't', VERSIONS => 1, COMPRESSION => 'NONE', BLOOMFILTER => 'ROW'}
0 row(s) in 0.3780 seconds
Hbase::Table - tsdb
create 'tsdb-tree',
{NAME => 't', VERSIONS => 1, COMPRESSION => 'NONE', BLOOMFILTER => 'ROW'}
0 row(s) in 0.4340 seconds
Hbase::Table - tsdb-tree
create 'tsdb-meta',
{NAME => 'name', COMPRESSION => 'NONE', BLOOMFILTER => 'ROW'}
0 row(s) in 0.3780 seconds
log
logback.xml 配置文件放入src目錄中即可
start
nohup /opt/opentsdb-2.3.0/build/tsdb tsd --config=/opt/opentsdb-2.3.0/src/opentsdb.conf >/dev/null 2>&1 &