Telegraf

    Telegraf is an open source tool. It contains over 200 plugins for gathering and writing different types of data written by people who work with that data.

    Ingest metrics using Telegraf plugin to TimescaleDB

    1. Check the version of Telegraf that you installed:

    2. Generate a sample configuration file for Telegraf using:

      A configuration file enables a CPU input plugin that samples various metrics about CPU usage, and the PostgreSQL output plugin. The file also includes all available input, output, processor, and aggregator plugins. These are commented out commented out by default. You can enable them as required.

    3. Test the sample configuration file telegraf.conf that you generated:

      1. telegraf --config telegraf.conf --test

      An output similar to this appears:

      1. 2022-11-28T12:53:44Z I! Starting Telegraf 1.24.3
      2. 2022-11-28T12:53:44Z I! Available plugins: 208 inputs, 9 aggregators, 26 processors, 20 parsers, 57 outputs
      3. 2022-11-28T12:53:44Z I! Loaded inputs: cpu
      4. 2022-11-28T12:53:44Z I! Loaded aggregators:
      1. 2022-11-28T12:53:44Z I! Loaded processors:
      1. 2022-11-28T12:53:44Z W! Outputs are not used in testing mode!
      2. 2022-11-28T12:53:44Z I! Tags enabled: host=localhost
      3. > cpu,cpu=cpu0,host=localhost usage_guest=0,usage_guest_nice=0,usage_idle=90.00000000087311,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=6.000000000040018,usage_user=3.999999999996362 1669640025000000000
      4. > cpu,cpu=cpu1,host=localhost usage_guest=0,usage_guest_nice=0,usage_idle=92.15686274495818,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=5.882352941192206,usage_user=1.9607843136712912 1669640025000000000
      5. > cpu,cpu=cpu2,host=localhost usage_guest=0,usage_guest_nice=0,usage_idle=91.99999999982538,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=3.999999999996362,usage_user=3.999999999996362 1669640025000000000
    1. Set the connection parameter in the [[outputs.postgresql]] section to the<SERVICE URL> of the TimescaleDB service that you created:

      1. connection = "<SERVICE URL>"
    1. Run Telegraf to collect the metrics:

      1. telegraf --config telegraf.conf

      The output uses loaded inputs cpuand outputs postgresql along with global tags, and the intervals with which the agent collects the data from the inputs, and flushes to the outputs.

      An output similar to this appears:

      1. 2022-12-05T12:32:00Z I! Starting Telegraf 1.24.3
      2. 2022-12-05T12:32:00Z I! Available plugins: 208 inputs, 9 aggregators, 26 processors, 20 parsers, 57 outputs
      3. 2022-12-05T12:32:00Z I! Loaded inputs: cpu
      4. 2022-12-05T12:32:00Z I! Loaded aggregators:
      1. 2022-12-05T12:32:00Z I! Loaded processors:
    2. Stop running Telegraf to collect the metrics after approximately 15 to 20 seconds.

      1. psql <SERVICE URL>
      2. Password for user tsdbadmin: <PASSWORD>
    3. View the metrics collected in the cpu table in tsdb:

      1. SELECT*FROM cpu;

      An output similar to this appears:

      1. time | cpu | host | usage_guest | usage_guest_nice | usage_idle | usage_iowait | usage_irq | usage_nice | usage_softirq | usage_steal | usage_system | usage_user
      1. ---------------------+-----------+----------------------------------+-------------+------------------+-------------------+--------------+-----------+------------+---------------+-------------+---------------------+---------------------
      2. 2022-12-05 12:25:20 | cpu0 | hostname | 0 | 0 | 83.08605341237833 | 0 | 0 | 0 | 0 | 0 | 6.824925815961274 | 10.089020771444481
      3. 2022-12-05 12:25:20 | cpu1 | hostname | 0 | 0 | 84.27299703278959 | 0 | 0 | 0 | 0 | 0 | 5.934718100814769 | 9.792284866395647
      4. 2022-12-05 12:25:20 | cpu3 | hostname| 0 | 0 | 86.68639053296472 | 0 | 0 | 0 | 0 | 0 | 4.43786982253345 | 8.875739645039992
      5. 2022-12-05 12:25:20 | cpu4 | hostname | 0 | 0 | 96.15384615371369 | 0 | 0 | 0 | 0 | 0 | 1.1834319526667423 | 2.6627218934917614
    4. To view the average usage per CPU core, use:

      1. SELECT cpu, avg(usage_user) FROM cpu GROUP BY cpu;

      An output similar to this appears:

      1. -----------+---------------------
      2. cpu-total | 2.7778985775548013
      3. cpu4 | 1.9990184779524285
      4. cpu2 | 4.083993994915682
      5. cpu0 | 5.281711648540422
      6. cpu1 | 4.9013756546309155
      7. cpu6 | 0.6719913538159535
      8. cpu5 | 1.0512637475474937
      9. cpu3 | 3.871919066617788

    For more information about the options that you can configure in Telegraf, see .

    1. Log in to Grafana and navigate to ConfigurationData sources. The data sources page lists previously configured data sources for the Grafana instance.
    2. Click Add data source to see a list of all supported data sources.
    3. Type PostgreSQL in the search field and click Select.
    4. Configure the data source:
      • In the Name field, type the name that you would like to use for the dataset.
      • In the PostgreSQL Connection section, type the Database, User, and Password fields using the .sql file that you downloaded when creating the TimescaleDB service.
      • In the Host field, type <HOST>:<PORT> from the .sql file that you downloaded.
      • Set TLS/SSL Mode to require.
      • In PostgreSQL details, enable TimescaleDB
    5. Click Save & test. If the connection is successful, is shown.

    When you have configured TimescaleDB as a data source in Grafana, you can create panels that are populated with data using SQL.