StatsD
StatsD is a simple daemon for aggregating and summarizing application metrics that has rapidly evolved in recent years into a unified protocol for collecting application performance metrics.
Simply fill in the domain name (or IP address) and corresponding port of the server running taosAdapter in the StatsD configuration file to write StatsD data into TDengine, fully leveraging TDengine's efficient storage, query performance, and cluster processing capabilities for time-series data.
Prerequisites
The following preparations are needed to write StatsD data into TDengine:
- TDengine cluster is deployed and running normally
- taosAdapter is installed and running normally. For details, please refer to the taosAdapter user manual
- StatsD is installed. For installation of StatsD, please refer to the official documentation
Configuration Steps
Configure taosAdapter
Method to configure taosAdapter to receive StatsD data:
- Enable the configuration item in the taosAdapter configuration file (default location /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
...
The default database name written by taosAdapter is statsd
, but you can also modify the db item in the taosAdapter configuration file to specify a different name. Fill in the user and password with the actual TDengine configuration values. After modifying the configuration file, taosAdapter needs to be restarted.
- You can also use taosAdapter command line arguments or set environment variables to enable the taosAdapter to receive StatsD data. For more details, please refer to the taosAdapter reference manual.
Configure StatsD
To use StatsD, download its source code. Modify its configuration file according to the example file exampleConfig.js
found in the root directory of the local source code download. Replace <taosAdapter's host> with the domain name or IP address of the server running taosAdapter, and <port for StatsD> with the port that taosAdapter uses to receive StatsD data (default is 6044).
Add to the backends section "./backends/repeater"
Add to the repeater section { host:'<taosAdapter's host>', port: <port for StatsD>}
Example configuration file:
{
port: 8125
, backends: ["./backends/repeater"]
, repeater: [{ host: '127.0.0.1', port: 6044}]
}
After adding the following content, start StatsD (assuming the configuration file is modified to config.js).
npm install
node stats.js config.js &
Verification Method
Run StatsD:
$ node stats.js config.js &
[1] 8546
$ 20 Apr 09:54:41 - [8546] reading config file: config.js
20 Apr 09:54:41 - server is up INFO
Use nc to write test data:
echo "foo:1|c" | nc -u -w0 127.0.0.1 8125
Use TDengine CLI to verify that data is written from StatsD to TDengine and can be correctly read:
taos> show databases;
name |
=================================
information_schema |
performance_schema |
statsd |
Query OK, 3 row(s) in set (0.003142s)
taos> use statsd;
Database changed.
taos> show stables;
name |
=================================
foo |
Query OK, 1 row(s) in set (0.002161s)
taos> select * from foo;
ts | value | metric_type |
=======================================================================================
2022-04-20 09:54:51.219614235 | 1 | counter |
Query OK, 1 row(s) in set (0.004179s)
taos>
- TDengine will automatically create unique IDs for subtable names by the rule.