taosAdapter 参考手册
taosAdapter 是一个 TDengine 的配套工具,是 TDengine 集群和应用程序之间的桥梁和适配器。它提供了一种易于使用和高效的方式来直接从数据收集代理软件(如 Telegraf、StatsD、collectd 等)摄取数据。它还提供了 InfluxDB/OpenTSDB 兼容的数据摄取接口,允许 InfluxDB/OpenTSDB 应用程序无缝移植到 TDengine。 TDengine 的各语言连接器通过 WebSocket 接口与 TDengine 进行通信,因此必须安装 taosAdapter。
架构图如下:
功能列表
taosAdapter 提供了以下功能:
- WebSocket 接口: 支持通过 WebSocket 协议执行 SQL、无模式数据写入、参数绑定和数据订阅功能。
- 兼容 InfluxDB v1 写接口: https://docs.influxdata.com/influxdb/v2.0/reference/api/influxdb-1x/write/
- 兼容 OpenTSDB JSON 和 telnet 格式写入:
- collectd 数据写入: collectd 是一个系统统计收集守护程序,请访问 https://collectd.org/ 了解更多信息。
- StatsD 数据写入: StatsD 是一个简单而强大的统计信息汇总的守护程序。请访问 https://github.com/statsd/statsd 了解更多信息。
- icinga2 OpenTSDB writer 数据写入: icinga2 是一个收集检查结果指标和性能数据的软件。请访问 https://icinga.com/docs/icinga-2/latest/doc/14-features/#opentsdb-writer 了解更多信息。
- TCollector 数据写入: TCollector是一个客户端进程,从本地收集器收集数据,并将数据推送到 OpenTSDB。请访问 http://opentsdb.net/docs/build/html/user_guide/utilities/tcollector.html 了解更多信息。
- node_exporter 采集写入: node_export 是一个机器指标的导出器。请访问 https://github.com/prometheus/node_exporter 了解更多信息。
- Prometheus remote_read 和 remote_write: remote_read 和 remote_write 是 Prometheus 数据读写分离的集群方案。请访问https://prometheus.io/blog/2019/10/10/remote-read-meets-streaming/#remote-apis 了解更多信息。
- RESTful 接口: RESTful API
WebSocket 接口
各语言连接器通过 taosAdapter 的 WebSocket 接口,能够实现 SQL 执行、无模式写入、参数绑定和数据订阅功能。参考 开发指南。
兼容 InfluxDB v1 写接口
您可以使用任何支持 HTTP 协议的客户端访问 Restful 接口地址 http://<fqdn>:6041/influxdb/v1/write
来写入 InfluxDB 兼容格式的数据到 TDengine。
支持 InfluxDB 参数如下:
db
指定 TDengine 使用的数据库名precision
TDengine 使用的时间精度u
TDengine 用户名p
TDengine 密码ttl
自动创建的子表生命周期,以子表的第一条数据的 TTL 参数为准,不可更新。更多信息请参考创建表文档的 TTL 参数。
注意: 目前不支持 InfluxDB 的 token 验证方式,仅支持 Basic 验证和查询参数验证。 示例:
curl --request POST http://127.0.0.1:6041/influxdb/v1/write?db=test --user "root:taosdata" --data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
兼容 OpenTSDB JSON 和 telnet 格式写入
您可以使用任何支持 HTTP 协议的客户端访问 Restful 接口地址 http://<fqdn>:6041/<APIEndPoint>
来写入 OpenTSDB 兼容格式的数据到 TDengine。EndPoint 如下:
/opentsdb/v1/put/json/<db>
/opentsdb/v1/put/telnet/<db>
collectd 数据写入
配置 taosAdapter
配置 taosAdapter 接收 collectd 数据的方法:
-
在 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 默认写入的数据库名称为
collectd
,也可以修改 taosAdapter 配置文件 dbs 项来指定不同的名称。user 和 password 填写实际 TDengine 配置的值。修改过配置文件 taosAdapter 需重新启动。 -
使用 taosAdapter 命令行参数或设置环境变量启动的方式,使能 taosAdapter 接收 collectd 数据功能,具体细节请参考 taosAdapter 的参考手册。
配置 collectd
collectd 使用插件机制可以以多种形式将采集到的监控数据写入到不同的数据存储软件。TDengine 支持直接采集插件和 write_tsdb 插件。
-
配置直接采集插件
修改 collectd 配置文件(默认位置 /etc/collectd/collectd.conf)相关配置项。
LoadPlugin network
<Plugin network>
Server "<taosAdapter's host>" "<port for collectd direct>"
</Plugin>其中 <taosAdapter's host> 填写运行 taosAdapter 的服务器域名或 IP 地址。<port for collectd direct> 填写 taosAdapter 用于接收 collectd 数据的端口(默认为 6045)。
示例如下:
LoadPlugin network
<Plugin network>
Server "127.0.0.1" "6045"
</Plugin> -
配置 write_tsdb 插件
修改 collectd 配置文件(默认位置 /etc/collectd/collectd.conf)相关配置项。
LoadPlugin write_tsdb
<Plugin write_tsdb>
<Node>
Host "<taosAdapter's host>"
Port "<port for collectd write_tsdb plugin>"
...
</Node>
</Plugin>其中 <taosAdapter's host> 填写运行 taosAdapter 的服务器域名或 IP 地址。<port for collectd write_tsdb plugin> 填写 taosAdapter 用于接收 collectd write_tsdb 插件的数据(默认为 6047)。
LoadPlugin write_tsdb
<Plugin write_tsdb>
<Node>
Host "127.0.0.1"
Port "6047"
HostTags "status=production"
StoreRates false
AlwaysAppendDS false
</Node>
</Plugin>然后重启 collectd:
systemctl restart collectd
StatsD 数据写入
配置 taosAdapter
配置 taosAdapter 接收 StatsD 数据的方法:
-
在 taosAdapter 配置文件(默认位置 /etc/taos/taosadapter.toml)中使能配置项
...
[statsd]
enable = true
port = 6044
db = "statsd"
user = "root"
password = "taosdata"
worker = 10
gatherInterval = "5s"
protocol = "udp"
maxTCPConnections = 250
tcpKeepAlive = false
allowPendingMessages = 50000
deleteCounters = true
deleteGauges = true
deleteSets = true
deleteTimings = true
...其中 taosAdapter 默认写入的数据库名称为
statsd
,也可以修改 taosAdapter 配置文件 db 项来指定不同的名称。user 和 password 填写实际 TDengine 配置的值。修改过配置文件 taosAdapter 需重新启动。 -
使用 taosAdapter 命令行参数或设置环境变量启动的方式,使能 taosAdapter 接收 StatsD 数据功能,具体细节请参考 taosAdapter 的参考手册
配置 StatsD
使用 StatsD 需要下载其源代码。其配置文件请参考其源代码下载到本地的根目录下的示例文件 exampleConfig.js
进行修改。其中 <taosAdapter's host> 填写运行 taosAdapter 的服务器域名或 IP 地址,<port for StatsD> 请填写 taosAdapter 接收 StatsD 数据的端口(默认为 6044)。
backends 部分添加 "./backends/repeater"
repeater 部分添加 { host:'<taosAdapter's host>', port: <port for StatsD>}
示例配置文件:
{
port: 8125
, backends: ["./backends/repeater"]
, repeater: [{ host: '127.0.0.1', port: 6044}]
}
增加如下内容后启动 StatsD(假设配置文件修改为 config.js)。
npm install
node stats.js config.js &
icinga2 OpenTSDB writer 数据写入
配置 taosAdapter
配置 taosAdapter 接收 icinga2 数据的方法:
-
在 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 默认写入的数据库名称为
icinga2
,也可以修改 taosAdapter 配置文件 dbs 项来指定不同的名称。user 和 password 填写实际 TDengine 配置的值。修改过 taosAdapter 需重新启动。 -
使用 taosAdapter 命令行参数或设置环境变量启动的方式,使能 taosAdapter 接收 icinga2 数据功能,具体细节请参考 taosAdapter 的参考手册
配置 icinga2
-
使能 icinga2 的 opentsdb-writer(参考链接 https://icinga.com/docs/icinga-2/latest/doc/14-features/#opentsdb-writer)
-
修改配置文件
/etc/icinga2/features-enabled/opentsdb.conf
填写 <taosAdapter's host> 为运行 taosAdapter 的服务器的域名或 IP 地址,<port for icinga2> 填写 taosAdapter 支持接收 icinga2 数据的相应端口(默认为 6048)object OpenTsdbWriter "opentsdb" {
host = "<taosAdapter's host>"
port = <port for icinga2>
}示例文件:
object OpenTsdbWriter "opentsdb" {
host = "127.0.0.1"
port = 6048
}
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 = 6049
MAX_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,