Telegraf is a client for collecting metrics from many inputs and has support for sending it on to various outputs. It is plugin-driven for the collection and delivery of data, so it is easily configurable and customizable. Telegraf is compiled as a standalone binary, which means there are no external dependencies required to manage.

QuestDB supports ingesting from Telegraf over both TCP and UDP. This page provides examples for collecting CPU and memory usage metrics using Telegraf and sends these metrics to a locally-running QuestDB instance for querying and visualization.

Prerequisites

Configuring Telegraf

As Telegraf is a plugin-driven agent, the configuration file provided when Telegraf is launched will determine which metrics to collect, if and how processing of the metrics should be performed, and the destination outputs.

The default location that Telegraf can pick up configuration files is /usr/local/etc/ on macOS and /etc/telegraf/ on Linux. After installation, default configuration files are in the following locations:

  • Homebrew install: /usr/local/etc/telegraf.conf
  • Linux, Deb and RPM: /etc/telegraf/telegraf.conf

Full configuration files for writing over TCP and UDP are provided below and can be placed in these directories and picked up by Telegraf. To view a comprehensive configuration file with example inputs and outputs, the following command can generate an example:

  1. telegraf -sample-config > example.conf

Example Inputs

The examples on this page will use input plugins that read CPU and memory usage statistics of the host machine and send this to the outputs specified in the configuration file. The following snippet includes code comments which describe the inputs in more detail:

  1. ...
  2. # -- INPUT PLUGINS -- #
  3. [[inputs.cpu]]
  4. # Read metrics about cpu usage
  5. ## Whether to report per-cpu stats or not
  6. percpu = true
  7. ## Whether to report total system cpu stats or not
  8. totalcpu = true
  9. ## If true, collect raw CPU time metrics
  10. collect_cpu_time = false
  11. ## If true, compute and report the sum of all non-idle CPU states
  12. report_active = false
  13. # Read metrics about memory usage
  14. [[inputs.mem]]
  15. # no customisation

Writing to QuestDB over TCP

QuestDB expects influx line protocol messages over TCP on port 9009. To change the default port, see the InfluxDB line protocol (TCP) section of the server configuration page.

Create a new file named questdb_tcp.conf in one of the locations Telegraf can load configuration files from and paste the following example:

  1. # Configuration for Telegraf agent
  2. [agent]
  3. ## Default data collection interval for all inputs
  4. interval = "5s"
  5. hostname = "qdb"
  6. # -- OUTPUT PLUGINS -- #
  7. [[outputs.socket_writer]]
  8. # Write metrics to a local QuestDB instance over TCP
  9. address = "tcp://127.0.0.1:9009"
  10. # -- INPUT PLUGINS -- #
  11. [[inputs.cpu]]
  12. percpu = true
  13. totalcpu = true
  14. collect_cpu_time = false
  15. report_active = false
  16. [[inputs.mem]]
  17. # no customisation

Run Telegraf and specify this config file with TCP writer settings:

  1. telegraf --config questdb_tcp.conf

Telegraf should report the following if configured correctly:

  1. 2021-01-29T12:11:32Z I! Loaded inputs: cpu mem
  2. 2021-01-29T12:11:32Z I! Loaded aggregators:
  3. 2021-01-29T12:11:32Z I! Loaded processors:
  4. 2021-01-29T12:11:32Z I! Loaded outputs: socket_writer
  5. ...

Writing to QuestDB over UDP

By default, QuestDB listens for multicast line protocol packets over UDP on 232.1.2.3:9009. To change the default ports that QuestDB is listening on, see the InfluxDB line protocol (UDP) section of the server configuration page.

Create a new file named questdb_udp.conf in one of the locations Telegraf can load configuration files from and paste the following example:

  1. # Configuration for Telegraf agent
  2. [agent]
  3. ## Default data collection interval for all inputs
  4. interval = "5s"
  5. hostname = "qdb"
  6. # -- OUTPUT PLUGINS -- #
  7. [[outputs.influxdb]]
  8. # Write metrics to a local QuestDB instance over UDP
  9. urls = ["udp://232.1.2.3:9009"]
  10. # -- INPUT PLUGINS -- #
  11. [[inputs.cpu]]
  12. percpu = true
  13. totalcpu = true
  14. collect_cpu_time = false
  15. report_active = false
  16. [[inputs.mem]]
  17. # no customisation

Run Telegraf and specify this config file with UDP writer settings:

  1. telegraf --config questdb_udp.conf

Telegraf should report the following

  1. 2021-01-29T13:36:28Z I! Loaded inputs: cpu mem
  2. 2021-01-29T13:36:28Z I! Loaded aggregators:
  3. 2021-01-29T13:36:28Z I! Loaded processors:
  4. 2021-01-29T13:36:28Z I! Loaded outputs: influxdb

Verifying the integration

  1. Navigate to the QuestDB Web Console at http://127.0.0.1:9000/. The Schema Navigator in the top left should display two new tables:
  • cpu generated from inputs.cpu
  • mem generated from inputs.mem
  1. Type cpu in the query editor and click RUN

The cpu table will have a column for each metric collected by the Telegraf plugin for monitoring memory:

import Screenshot from “@theme/Screenshot”

Graphing system CPU

To create a graph that visualizes CPU usage over time, run the following example query:

  1. SELECT
  2. avg(usage_system) cpu_average,
  3. max(usage_system) cpu_max,
  4. timestamp
  5. FROM cpu SAMPLE BY 1m;

Select the Chart tab and set the following values:

  • Chart type line
  • Labels timestamp
  • Series cpu_average and cpu_max