TCollector 是 openTSDB 的一部分,它用來采集客戶端日志發送給數據庫。
只需要將 TCollector 的配置修改指向運行 taosAdapter 的服務器域名(或 IP 地址)和相應端口即可將 TCollector 采集的數據存在到 TDengine 中,可以充分利用 TDengine 對時序數據的高效存儲查詢性能和集群處理能力。
前置條件
要將 TCollector 數據寫入 TDengine 需要以下幾方面的準備工作。
- TDengine 集群已經部署并正常運行
- taosAdapter 已經安裝并正常運行。具體細節請參考 taosAdapter 的使用手冊
- TCollector 已經安裝。安裝 TCollector 請參考 官方文檔
配置步驟
配置 taosAdapter
配置 taosAdapter 接收 TCollector 數據的方法:
-
在 taosAdapter 配置文件(默認位置 /etc/taos/taosadapter.toml)中使能配置項
... [opentsdb_telnet] enable = true maxTCPConnections = 250 tcpKeepAlive = false dbs = ["opentsdb_telnet", "collectd", "icinga2", "tcollector"] ports = [6046, 6047, 6048, 6049] user = "root" password = "taosdata" ...
其中 taosAdapter 默認寫入的數據庫名稱為
tcollector
,也可以修改 taosAdapter 配置文件 dbs 項來指定不同的名稱。user 和 password 填寫實際 TDengine 配置的值。修改過配置文件 taosAdapter 需重新啟動。 -
使用 taosAdapter 命令行參數或設置環境變量啟動的方式,使能 taosAdapter 接收 tcollector 數據功能,具體細節請參考 taosAdapter 的參考手冊
配置 TCollector
使用 TCollector 需下載其源代碼。其配置項在其源代碼中。注意:TCollector 各個版本區別較大,這里僅以當前 master 分支最新代碼 (git commit: 37ae920) 為例。
修改 collectors/etc/config.py
和 tcollector.py
兩個文件中相應內容。將原指向 OpenTSDB 宿主機的地址修改為 taosAdapter 被部署的服務器域名或 IP 地址,修改端口為 taosAdapter 支持 TCollector 使用的相應端口(默認為 6049)。
示例為源代碼修改內容的 git diff 輸出:
index e7e7a1c..ec3e23c 100644
--- a/collectors/etc/config.py
+++ b/collectors/etc/config.py
@@ -59,13 +59,13 @@ def get_defaults():'http_password': False,'reconnectinterval': 0,'http_username': False,
- 'port': 4242,
+ 'port': 6049,'pidfile': '/var/run/tcollector.pid','http': False,'http_api_path': "api/put",'tags': [],'remove_inactive_collectors': False,
- 'host': '',
+ 'host': '127.0.0.1','logfile': '/var/log/tcollector.log','cdir': default_cdir,'ssl': False,
diff --git a/tcollector.py b/tcollector.py
index 21f9b23..4c71ba2 100755
--- a/tcollector.py
+++ b/tcollector.py
@@ -64,7 +64,7 @@ ALIVE = True# exceptions, something is not right and tcollector will shutdown.# Hopefully some kind of supervising daemon will then restart it.MAX_UNCAUGHT_EXCEPTIONS = 100
-DEFAULT_PORT = 4242
+DEFAULT_PORT = 6049MAX_REASONABLE_TIMESTAMP = 2209212000 # Good until Tue 3 Jan 14:00:00 GMT 2040# How long to wait for datapoints before assuming# a collector is dead and restarting it
@@ -943,13 +943,13 @@ def parse_cmdline(argv):'http_password': False,'reconnectinterval': 0,'http_username': False,
- 'port': 4242,
+ 'port': 6049,'pidfile': '/var/run/tcollector.pid','http': False,'http_api_path': "api/put",'tags': [],'remove_inactive_collectors': False,
- 'host': '',
+ 'host': '127.0.0.1','logfile': '/var/log/tcollector.log','cdir': default_cdir,'ssl': False,
驗證方法
重啟 taosAdapter:
sudo systemctl restart taosadapter
手動執行 sudo ./tcollector.py
等待數秒后使用 TDengine CLI 查詢 TDengine 是否創建相應數據庫并寫入數據。
taos> show databases;name |
=================================information_schema |performance_schema |tcollector |
Query OK, 3 rows in database (0.001647s)taos> use tcollector;
Database changed.taos> show stables;name |
=================================proc.meminfo.hugepages_rsvd |proc.meminfo.directmap1g |proc.meminfo.vmallocchunk |proc.meminfo.hugepagesize |tcollector.reader.lines_dro... |proc.meminfo.sunreclaim |proc.stat.ctxt |proc.meminfo.swaptotal |proc.uptime.total |tcollector.collector.lines_... |proc.meminfo.vmallocused |proc.meminfo.memavailable |sys.numa.foreign_allocs |proc.meminfo.committed_as |proc.vmstat.pswpin |proc.meminfo.cmafree |proc.meminfo.mapped |proc.vmstat.pgmajfault |
...
提示:
- TDengine 默認生成的子表名是根據規則生成的唯一 ID 值。