Telegraf writing

Telegraf is a viral, open-source, metrics collection software. Telegraf can collect the operation information of various components without having to write any scripts to collect regularly, reducing the difficulty of data acquisition.

Telegraf’s data can be written to TDengine by simply adding the output configuration of Telegraf to the URL corresponding to taosAdapter and modifying several configuration items. The presence of Telegraf data in TDengine can take advantage of TDengine’s efficient storage query performance and clustering capabilities for time-series data.

Prerequisites

To write Telegraf data to TDengine requires the following preparations.

  • The TDengine cluster is deployed and functioning properly
  • taosAdapter is installed and running properly. Please refer to the taosAdapter manual for details.
  • Telegraf has been installed. Please refer to the official documentation for Telegraf installation.

Configuration steps

In the Telegraf configuration file (default location /etc/telegraf/telegraf.conf) add an outputs.http section.

  1. [[outputs.http]]
  2. url = "http://<taosAdapter's host>:<REST service port>/influxdb/v1/write?db=<database name>"
  3. ...
  4. username = "<TDengine's username>"
  5. password = "<TDengine's password>"
  6. ...

Where <taosAdapter’s host> please fill in the server’s domain name or IP address running the taosAdapter service. <REST service port> please fill in the port of the REST service (default is 6041). <TDengine’s username> and <TDengine’s password> please fill in the actual configuration of the currently running TDengine. And <database name> please fill in the database name where you want to store Telegraf data in TDengine.

An example is as follows.

  1. [[outputs.http]]
  2. url = "http://127.0.0.1:6041/influxdb/v1/write?db=telegraf"
  3. method = "POST"
  4. timeout = "5s"
  5. username = "root"
  6. password = "taosdata"
  7. data_format = "influx"

Verification method

Restart Telegraf service:

  1. sudo systemctl restart telegraf

Use TDengine CLI to verify Telegraf correctly writing data to TDengine and read out:

  1. taos> show databases;
  2. name | created_time | ntables | vgroups | replica | quorum | days | keep | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | cachelast | precision | update | status |
  3. ====================================================================================================================================================================================================================================================================================
  4. telegraf | 2022-04-20 08:47:53.488 | 22 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ns | 2 | ready |
  5. log | 2022-04-20 07:19:50.260 | 9 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ms | 0 | ready |
  6. Query OK, 2 row(s) in set (0.002401s)
  7. taos> use telegraf;
  8. Database changed.
  9. taos> show stables;
  10. name | created_time | columns | tags | tables |
  11. ============================================================================================
  12. swap | 2022-04-20 08:47:53.532 | 7 | 1 | 1 |
  13. cpu | 2022-04-20 08:48:03.488 | 11 | 2 | 5 |
  14. system | 2022-04-20 08:47:53.512 | 8 | 1 | 1 |
  15. diskio | 2022-04-20 08:47:53.550 | 12 | 2 | 15 |
  16. kernel | 2022-04-20 08:47:53.503 | 6 | 1 | 1 |
  17. mem | 2022-04-20 08:47:53.521 | 35 | 1 | 1 |
  18. processes | 2022-04-20 08:47:53.555 | 12 | 1 | 1 |
  19. disk | 2022-04-20 08:47:53.541 | 8 | 5 | 2 |
  20. Query OK, 8 row(s) in set (0.000521s)
  21. taos> select * from telegraf.system limit 10;
  22. ts | load1 | load5 | load15 | n_cpus | n_users | uptime | uptime_format | host
  23. |
  24. =============================================================================================================================================================================================================================================
  25. 2022-04-20 08:47:50.000000000 | 0.000000000 | 0.050000000 | 0.070000000 | 4 | 1 | 5533 | 1:32 | shuduo-1804
  26. |
  27. 2022-04-20 08:48:00.000000000 | 0.000000000 | 0.050000000 | 0.070000000 | 4 | 1 | 5543 | 1:32 | shuduo-1804
  28. |
  29. 2022-04-20 08:48:10.000000000 | 0.000000000 | 0.040000000 | 0.070000000 | 4 | 1 | 5553 | 1:32 | shuduo-1804
  30. |
  31. Query OK, 3 row(s) in set (0.013269s)