taosAdapter
taosAdapter 是一個 TDengine 的配套工具,是 TDengine 集群和應用程序之間的橋梁和適配器。它提供了一種易于使用和高效的方式來直接從數據收集代理軟件(如 Telegraf、StatsD、collectd 等)攝取數據。它還提供了 InfluxDB/OpenTSDB 兼容的數據攝取接口,允許 InfluxDB/OpenTSDB 應用程序無縫移植到 TDengine。
taosAdapter提供以下功能:
- RESTful 接口
- 兼容 InfluxDB v1寫接口
- 兼容 OpenTSDB JSON 和 telnet 格式寫入
- 無縫連接到 Telegraf
- 無縫連接到 collectd
- 無縫連接到 StatsD
- 支持 Prometheus remote_read 和 remote_write
taosAdapter 架構圖

taosAdapter 部署方法
安裝 taosAdapter
taosAdapter 從 TDengine v2.4.0.0 版本開始成為 TDengine 服務端軟件 的一部分,如果您使用 TDengine server 您不需要任何額外的步驟來安裝 taosAdapter。您可以從下載TDengine server(taosAdapter 包含在 v2.4.0.0 及以上版本)安裝包。如果需要將 taosAdapter 分離部署在 TDengine server 之外的服務器上,則應該在該服務器上安裝完整的 TDengine 來安裝 taosAdapter。如果您需要使用源代碼編譯生成 taosAdapter,您可以參考文檔。
start/stop taosAdapter
在 Linux 系統上 taosAdapter 服務默認由 systemd 管理。使用命令 systemctl start taosadapter 可以啟動 taosAdapter 服務。使用命令 systemctl stop taosadapter 可以停止 taosAdapter 服務。
移除 taosAdapter
使用命令 rmtaos 可以移除包括 taosAdapter 在內的 TDengine server 軟件。
升級 taosAdapter
taosAdapter 和 TDengine server 需要使用相同版本。請通過升級 TDengine server 來升級 taosAdapter。 與taosd分離部署的taosAdapter必須通過升級其所在服務器的TDengine server才能得到升級。
taosAdapter 參數列表
taosAdapter 支持通過命令行參數、環境變量和配置文件來進行配置。默認配置文件是 /etc/taos/taosadapter.toml。
命令行參數優先于環境變量優先于配置文件,命令行用法是arg=val,如 taosadapter -p=30000 --debug=true,詳細列表如下:
Usage of taosAdapter:
--collectd.db string collectd db name. Env "TAOS_ADAPTER_COLLECTD_DB" (default "collectd")
--collectd.enable enable collectd. Env "TAOS_ADAPTER_COLLECTD_ENABLE" (default true)
--collectd.password string collectd password. Env "TAOS_ADAPTER_COLLECTD_PASSWORD" (default "taosdata")
--collectd.port int collectd server port. Env "TAOS_ADAPTER_COLLECTD_PORT" (default 6045)
--collectd.user string collectd user. Env "TAOS_ADAPTER_COLLECTD_USER" (default "root")
--collectd.worker int collectd write worker. Env "TAOS_ADAPTER_COLLECTD_WORKER" (default 10)
-c, --config string config path default /etc/taos/taosadapter.toml
--cors.allowAllOrigins cors allow all origins. Env "TAOS_ADAPTER_CORS_ALLOW_ALL_ORIGINS" (default true)
--cors.allowCredentials cors allow credentials. Env "TAOS_ADAPTER_CORS_ALLOW_Credentials"
--cors.allowHeaders stringArray cors allow HEADERS. Env "TAOS_ADAPTER_ALLOW_HEADERS"
--cors.allowOrigins stringArray cors allow origins. Env "TAOS_ADAPTER_ALLOW_ORIGINS"
--cors.allowWebSockets cors allow WebSockets. Env "TAOS_ADAPTER_CORS_ALLOW_WebSockets"
--cors.exposeHeaders stringArray cors expose headers. Env "TAOS_ADAPTER_Expose_Headers"
--debug enable debug mode. Env "TAOS_ADAPTER_DEBUG"
--help Print this help message and exit
--influxdb.enable enable influxdb. Env "TAOS_ADAPTER_INFLUXDB_ENABLE" (default true)
--log.path string log path. Env "TAOS_ADAPTER_LOG_PATH" (default "/var/log/taos")
--log.rotationCount uint log rotation count. Env "TAOS_ADAPTER_LOG_ROTATION_COUNT" (default 30)
--log.rotationSize string log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_ROTATION_SIZE" (default "1GB")
--log.rotationTime duration log rotation time. Env "TAOS_ADAPTER_LOG_ROTATION_TIME" (default 24h0m0s)
--logLevel string log level (panic fatal error warn warning info debug trace). Env "TAOS_ADAPTER_LOG_LEVEL" (default "info")
--monitor.collectDuration duration Set monitor duration. Env "TAOS_MONITOR_COLLECT_DURATION" (default 3s)
--monitor.identity string The identity of the current instance, or 'hostname:port' if it is empty. Env "TAOS_MONITOR_IDENTITY"
--monitor.incgroup Whether running in cgroup. Env "TAOS_MONITOR_INCGROUP"
--monitor.password string TDengine password. Env "TAOS_MONITOR_PASSWORD" (default "taosdata")
--monitor.pauseAllMemoryThreshold float Memory percentage threshold for pause all. Env "TAOS_MONITOR_PAUSE_ALL_MEMORY_THRESHOLD" (default 80)
--monitor.pauseQueryMemoryThreshold float Memory percentage threshold for pause query. Env "TAOS_MONITOR_PAUSE_QUERY_MEMORY_THRESHOLD" (default 70)
--monitor.user string TDengine user. Env "TAOS_MONITOR_USER" (default "root")
--monitor.writeInterval duration Set write to TDengine interval. Env "TAOS_MONITOR_WRITE_INTERVAL" (default 30s)
--monitor.writeToTD Whether write metrics to TDengine. Env "TAOS_MONITOR_WRITE_TO_TD" (default true)
--node_exporter.caCertFile string node_exporter ca cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CA_CERT_FILE"
--node_exporter.certFile string node_exporter cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CERT_FILE"
--node_exporter.db string node_exporter db name. Env "TAOS_ADAPTER_NODE_EXPORTER_DB" (default "node_exporter")
--node_exporter.enable enable node_exporter. Env "TAOS_ADAPTER_NODE_EXPORTER_ENABLE"
--node_exporter.gatherDuration duration node_exporter gather duration. Env "TAOS_ADAPTER_NODE_EXPORTER_GATHER_DURATION" (default 5s)
--node_exporter.httpBearerTokenString string node_exporter http bearer token. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_BEARER_TOKEN_STRING"
--node_exporter.httpPassword string node_exporter http password. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_PASSWORD"
--node_exporter.httpUsername string node_exporter http username. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_USERNAME"
--node_exporter.insecureSkipVerify node_exporter skip ssl check. Env "TAOS_ADAPTER_NODE_EXPORTER_INSECURE_SKIP_VERIFY" (default true)
--node_exporter.keyFile string node_exporter cert key file path. Env "TAOS_ADAPTER_NODE_EXPORTER_KEY_FILE"
--node_exporter.password string node_exporter password. Env "TAOS_ADAPTER_NODE_EXPORTER_PASSWORD" (default "taosdata")
--node_exporter.responseTimeout duration node_exporter response timeout. Env "TAOS_ADAPTER_NODE_EXPORTER_RESPONSE_TIMEOUT" (default 5s)
--node_exporter.urls strings node_exporter urls. Env "TAOS_ADAPTER_NODE_EXPORTER_URLS" (default [//localhost:9100])
--node_exporter.user string node_exporter user. Env "TAOS_ADAPTER_NODE_EXPORTER_USER" (default "root")
--opentsdb.enable enable opentsdb. Env "TAOS_ADAPTER_OPENTSDB_ENABLE" (default true)
--opentsdb_telnet.dbs strings opentsdb_telnet db names. Env "TAOS_ADAPTER_OPENTSDB_TELNET_DBS" (default [opentsdb_telnet,collectd_tsdb,icinga2_tsdb,tcollector_tsdb])
--opentsdb_telnet.enable enable opentsdb telnet,warning: without auth info(default false). Env "TAOS_ADAPTER_OPENTSDB_TELNET_ENABLE"
--opentsdb_telnet.maxTCPConnections int max tcp connections. Env "TAOS_ADAPTER_OPENTSDB_TELNET_MAX_TCP_CONNECTIONS" (default 250)
--opentsdb_telnet.password string opentsdb_telnet password. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PASSWORD" (default "taosdata")
--opentsdb_telnet.ports ints opentsdb telnet tcp port. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PORTS" (default [6046,6047,6048,6049])
--opentsdb_telnet.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TCP_KEEP_ALIVE"
--opentsdb_telnet.user string opentsdb_telnet user. Env "TAOS_ADAPTER_OPENTSDB_TELNET_USER" (default "root")
--pool.idleTimeout duration Set idle connection timeout. Env "TAOS_ADAPTER_POOL_IDLE_TIMEOUT" (default 1h0m0s)
--pool.maxConnect int max connections to taosd. Env "TAOS_ADAPTER_POOL_MAX_CONNECT" (default 4000)
--pool.maxIdle int max idle connections to taosd. Env "TAOS_ADAPTER_POOL_MAX_IDLE" (default 4000)
-P, --port int http port. Env "TAOS_ADAPTER_PORT" (default 6041)
--prometheus.enable enable prometheus. Env "TAOS_ADAPTER_PROMETHEUS_ENABLE" (default true)
--restfulRowLimit int restful returns the maximum number of rows (-1 means no limit). Env "TAOS_ADAPTER_RESTFUL_ROW_LIMIT" (default -1)
--ssl.certFile string ssl cert file path. Env "TAOS_ADAPTER_SSL_CERT_FILE"
--ssl.enable enable ssl. Env "TAOS_ADAPTER_SSL_ENABLE"
--ssl.keyFile string ssl key file path. Env "TAOS_ADAPTER_SSL_KEY_FILE"
--statsd.allowPendingMessages int statsd allow pending messages. Env "TAOS_ADAPTER_STATSD_ALLOW_PENDING_MESSAGES" (default 50000)
--statsd.db string statsd db name. Env "TAOS_ADAPTER_STATSD_DB" (default "statsd")
--statsd.deleteCounters statsd delete counter cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_COUNTERS" (default true)
--statsd.deleteGauges statsd delete gauge cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_GAUGES" (default true)
--statsd.deleteSets statsd delete set cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_SETS" (default true)
--statsd.deleteTimings statsd delete timing cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_TIMINGS" (default true)
--statsd.enable enable statsd. Env "TAOS_ADAPTER_STATSD_ENABLE" (default true)
--statsd.gatherInterval duration statsd gather interval. Env "TAOS_ADAPTER_STATSD_GATHER_INTERVAL" (default 5s)
--statsd.maxTCPConnections int statsd max tcp connections. Env "TAOS_ADAPTER_STATSD_MAX_TCP_CONNECTIONS" (default 250)
--statsd.password string statsd password. Env "TAOS_ADAPTER_STATSD_PASSWORD" (default "taosdata")
--statsd.port int statsd server port. Env "TAOS_ADAPTER_STATSD_PORT" (default 6044)
--statsd.protocol string statsd protocol [tcp or udp]. Env "TAOS_ADAPTER_STATSD_PROTOCOL" (default "udp")
--statsd.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_STATSD_TCP_KEEP_ALIVE"
--statsd.user string statsd user. Env "TAOS_ADAPTER_STATSD_USER" (default "root")
--statsd.worker int statsd write worker. Env "TAOS_ADAPTER_STATSD_WORKER" (default 10)
--taosConfigDir string load taos client config path. Env "TAOS_ADAPTER_TAOS_CONFIG_FILE"
--version Print the version and exit
備注: 使用瀏覽器進行接口調用請根據實際情況設置如下跨源資源共享(CORS)參數:
AllowAllOrigins
AllowOrigins
AllowHeaders
ExposeHeaders
AllowCredentials
AllowWebSockets
如果不通過瀏覽器進行接口調用無需關心這幾項配置。
關于 CORS 協議細節請參考: 或 。
示例配置文件參見 。
功能列表
- 與 RESTful 接口兼容 //www.yakult-sh.com.cn/cn/documentation/connector#restful
- 兼容 InfluxDB v1 寫接口
- 兼容 OpenTSDB JSON 和 telnet 格式寫入
- 與collectd無縫連接 collectd 是一個系統統計收集守護程序,請訪問 了解更多信息。
- Seamless connection with StatsD StatsD 是一個簡單而強大的統計信息匯總的守護程序。請訪問 了解更多信息。
- 與 icinga2 的無縫連接 icinga2 是一個收集檢查結果指標和性能數據的軟件。請訪問 了解更多信息。
- 與 tcollector 無縫連接 TCollector是一個客戶端進程,從本地收集器收集數據,并將數據推送到OpenTSDB。請訪問 了解更多信息。
- 無縫連接 node_exporter node_export 是一個機器指標的導出器。請訪問 了解更多信息。
- 支持 Prometheus remote_read 和 remote_write remote_read 和 remote_write 是 Prometheus 數據讀寫分離的集群方案。請訪問 了解更多信息。
接口
TDengine RESTful 接口
您可以使用任何支持 http 協議的客戶端通過訪問 RESTful 接口地址 //<fqdn>:6041/<APIEndPoint> 來寫入數據到 TDengine 或從 TDengine 中查詢數據。細節請參考官方文檔。支持如下 EndPoint :
/rest/sql
/rest/sqlt
/rest/sqlutc
InfluxDB
您可以使用任何支持 http 協議的客戶端訪問 Restful 接口地址 //<fqdn>:6041/<APIEndPoint> 來寫入 InfluxDB 兼容格式的數據到 TDengine。EndPoint 如下:
/influxdb/v1/write
支持 InfluxDB 查詢參數如下:
db指定 TDengine 使用的數據庫名precisionTDengine 使用的時間精度uTDengine 用戶名pTDengine 密碼
注意: 目前不支持 InfluxDB 的 token 驗證方式只支持 Basic 驗證和查詢參數驗證。
OpenTSDB
您可以使用任何支持 http 協議的客戶端訪問 Restful 接口地址 //<fqdn>:6041/<APIEndPoint> 來寫入 OpenTSDB 兼容格式的數據到 TDengine。EndPoint 如下:
/opentsdb/v1/put/json/<db>
/opentsdb/v1/put/telnet/<db>
collectd
直接采集
修改 collectd 配置文件 /etc/collectd/collectd.conf,taosAdapter 默認使用端口 6045 來接收 collectd 直接采集方式的數據。
LoadPlugin network
<Plugin network>
Server "127.0.0.1" "6045"
</Plugin>
tsdb 寫入方式
修改 collectd 配置文件 /etc/collectd/collectd.conf,taosAdapter 默認使用端口 6047 來接收 collectd tsdb 寫入方式的數據。
LoadPlugin write_tsdb
<Plugin write_tsdb>
<Node>
Host "localhost"
Port "6047"
HostTags "status=production"
StoreRates false
AlwaysAppendDS false
</Node>
</Plugin>
StatsD
修改 StatsD 配置文件 config.js,taosAdapter 默認使用 6044 端口接收 StatsD 的寫入數據。
backendsadd"./backends/repeater"repeateradd{ host:'host to taosAdapter', port: 6044}
配置文件示例
{
port: 8125,
backends: ["./backends/repeater"],
repeater: [{ host: '127.0.0.1', port: 6044}]
}
icinga2 OpenTSDB writer
使用 icinga2 收集監控數據的方法參見:
- 參考文檔: opentsdb-writer
- 使能 taosAdapter
opentsdb_telnet.enable來支持寫入 - 修改配置文件
/etc/icinga2/features-enabled/opentsdb.conf, taosAdapter 默認使用 6048 端口接收 icinga2 的數據。
object OpenTsdbWriter "opentsdb" {
host = "host to taosAdapter"
port = 6048
}
TCollector
Tcollector 是一個客戶端進程,它從本地收集器中收集數據并將數據推送到 OpenTSDB。您在您的所有主機上運行它,它完成將每個主機的數據發送到 TSD (OpenTSDB 后臺服務進程)的工作。
- 啟用 taosAdapter 配置 opentsdb_telnet.enable
- 修改 TCollector 配置文件,將 OpenTSDB 主機修改為部署 taosAdapter 的主機,并修改端口為6049
node_exporter
Prometheus 使用的由*NIX內核暴露的硬件和操作系統指標的輸出器
- 啟用 taosAdapter 的配置 node_exporter.enable
- 設置 node_exporter 的相關配置
- 重新啟動 taosAdapter
prometheus
remote_read 和 remote_write 是 Prometheus 數據讀寫分離的集群方案。 只需要將 remote_read 和 remote_write url 指向 taosAdapter 對應的 url 同時設置 Basic 驗證即可使用。
- remote_read url :
//host_to_taosAdapter:port(default 6041)/prometheus/v1/remote_read/:db - remote_write url :
//host_to_taosAdapter:port(default 6041)/prometheus/v1/remote_write/:db
Basic驗證:
- username: TDengine 連接用戶名
- password: TDengine 連接密碼
示例 prometheus.yml 如下:
remote_write:
- url: "//localhost:6041/prometheus/v1/remote_write/prometheus_data"
basic_auth:
username: root
password: taosdata
remote_read:
- url: "//localhost:6041/prometheus/v1/remote_read/prometheus_data"
basic_auth:
username: root
password: taosdata
remote_timeout: 10s
read_recent: true
內存使用優化方法
taosAdapter 將監測自身運行過程中內存使用率并通過兩個閾值進行調節。有效值范圍為 -1 到 100 的整數,單位為系統物理內存的百分比。
- pauseQueryMemoryThreshold
- pauseAllMemoryThreshold
當超過 pauseQueryMemoryThreshold 閾值時時停止處理查詢請求。
http 返回內容:
- code 503
- body "query memory exceeds threshold"
當超過 pauseAllMemoryThreshold 閾值時停止處理所有寫入和查詢請求。
http 返回內容:
- code 503
- body "memory exceeds threshold"
當內存回落到閾值之下時恢復對應功能。
狀態檢查接口 //<fqdn>:6041/-/ping
- 正常返回
code 200 - 無參數 如果內存超過 pauseAllMemoryThreshold 將返回
code 503 - 請求參數
action=query如果內存超過 pauseQueryMemoryThreshold 或 pauseAllMemoryThreshold 將返回code 503
對應配置參數
monitor.collectDuration 監測間隔 環境變量 "TAOS_MONITOR_COLLECT_DURATION" (默認值 3s)
monitor.incgroup 是否是cgroup中運行(容器中運行設置為 true) 環境變量 "TAOS_MONITOR_INCGROUP"
monitor.pauseAllMemoryThreshold 不再進行插入和查詢的內存閾值 環境變量 "TAOS_MONITOR_PAUSE_ALL_MEMORY_THRESHOLD" (默認值 80)
monitor.pauseQueryMemoryThreshold 不再進行查詢的內存閾值 環境變量 "TAOS_MONITOR_PAUSE_QUERY_MEMORY_THRESHOLD" (默認值 70)
您可以根據具體項目應用場景和運營策略進行相應調整,并建議使用運營監控軟件及時進行系統內存狀態監控。負載均衡器也可以通過這個接口檢查 taosAdapter 運行狀態。
taosAdapter 監控指標
taosAdapter 采集 http 相關指標、cpu 百分比和內存百分比。
http 接口
提供符合 接口:
//<fqdn>:6041/metrics
寫入 TDengine
taosAdapter 支持將 http 監控、cpu 百分比和內存百分比寫入 TDengine。
有關配置參數
| 配置項 | 描述 | 默認值 |
|---|---|---|
| monitor.collectDuration | cpu 和內存采集間隔 | 3s |
| monitor.identity | 當前taosadapter 的標識符如果不設置將使用 'hostname:port' | |
| monitor.incgroup | 是否是 cgroup 中運行(容器中運行設置為 true) | false |
| monitor.writeToTD | 是否寫入到 TDengine | true |
| monitor.user | TDengine 連接用戶名 | root |
| monitor.password | TDengine 連接密碼 | taosdata |
| monitor.writeInterval | 寫入TDengine 間隔 | 30s |
結果返回條數限制
taosAdapter 通過參數 restfulRowLimit 來控制結果的返回條數,-1 代表無限制,默認無限制。
該參數控制以下接口返回
//<fqdn>:6041/rest/sql//<fqdn>:6041/rest/sqlt//<fqdn>:6041/rest/sqlutc//<fqdn>:6041/prometheus/v1/remote_read/:db
故障解決
您可以通過命令 systemctl status taosadapter 來檢查 taosAdapter 運行狀態。
您也可以通過設置 --logLevel 參數或者環境變量 TAOS_ADAPTER_LOG_LEVEL 來調節 taosAdapter 日志輸出詳細程度。有效值包括: panic、fatal、error、warn、warning、info、debug以及trace。
如何從舊版本 TDengine 遷移到 taosAdapter
在 TDengine server 2.2.x.x 或更早期版本中,taosd 進程包含一個內嵌的 http 服務。如前面所述,taosAdapter 是一個使用 systemd 管理的獨立軟件,擁有自己的進程。并且兩者有一些配置參數和行為是不同的,請見下表:
| # | embedded httpd | taosAdapter | comment |
|---|---|---|---|
| 1 | httpEnableRecordSql | --logLevel=debug | |
| 2 | httpMaxThreads | n/a | taosAdapter 自動管理線程池,無需此參數 |
| 3 | telegrafUseFieldNum | 請參考 taosAdapter telegraf 配置方法 | |
| 4 | restfulRowLimit | restfulRowLimit | 內嵌 httpd 默認輸出 10240 行數據,最大允許值為 102400。taosAdapter 也提供 restfulRowLimit 但是默認不做限制。您可以根據實際場景需求進行配置 |
| 5 | httpDebugFlag | 不適用 | httpdDebugFlag 對 taosAdapter 不起作用 |
| 6 | httpDBNameMandatory | 不適用 | taosAdapter 要求 URL 中必須指定數據庫名 |

