Location>code7788 >text

Summary of common telegraf commands

Popularity:256 ℃/2024-08-01 11:17:36

Telegraf is a flexible server agent for collecting and reporting metrics. It supports plugin drivers, which means you can add or modify functionality as needed.

1. Use telegraf --help to view the relevant commands and parameters provided by telegraf.

Use telegraf --help to see the relevant commands and parameters provided by telegraf as follows:

telegraf --help
Telegraf, The plugin-driven server agent for collecting and reporting metrics.

Usage:

  telegraf [commands|flags]

The commands & flags are:

  config              print out full sample configuration to stdout
  version             print the version to stdout

  --aggregator-filter <filter>   filter the aggregators to enable, separator is :
  --config <file>                configuration file to load
  --config-directory <directory> directory containing additional *.conf files
  --plugin-directory             directory containing *.so files, this directory will be
                                 searched recursively. Any Plugin found will be loaded
                                 and namespaced.
  --debug                        turn on debug logging
  --input-filter <filter>        filter the inputs to enable, separator is :
  --input-list                   print available input plugins.
  --output-filter <filter>       filter the outputs to enable, separator is :
  --output-list                  print available output plugins.
  --pidfile <file>               file to write our pid to
  --pprof-addr <address>         pprof address to listen on, don't activate pprof if empty
  --processor-filter <filter>    filter the processors to enable, separator is :
  --quiet                        run in quiet mode
  --section-filter               filter config sections to output, separator is :
                                 Valid values are 'agent', 'global_tags', 'outputs',
                                 'processors', 'aggregators' and 'inputs'
  --sample-config                print out full sample configuration
  --test                         gather metrics, print them out, and exit;
                                 processors, aggregators, and outputs are not run
  --test-wait                    wait up to this many seconds for service
                                 inputs to complete in test mode
  --usage <plugin>               print usage for a plugin, ie, 'telegraf --usage mysql'
  --version                      display the version and exit

Examples:

  # generate a telegraf config file:
  telegraf config > 

  # generate config with only cpu input & influxdb output plugins defined
  telegraf --input-filter cpu --output-filter influxdb config

  # run a single telegraf collection, outputing metrics to stdout
  telegraf --config  --test

  # run telegraf with all plugins defined in config file
  telegraf --config 

  # run telegraf, enabling the cpu & memory input, and influxdb output plugins
  telegraf --config  --input-filter cpu:mem --output-filter influxdb

  # run telegraf with pprof
  telegraf --config  --pprof-addr localhost:6060

basic command

  • telegraf config: Prints the complete sample configuration to standard output.

  • telegraf version: Prints version information.

Configuration

  • --config <file>: Specifies the configuration file to be loaded.

  • --config-directory <directory>: Specify the directory containing the additional *.conf files.

  • --plugin-directory: Specify a directory containing *.so files, and Telegraf will recursively search this directory and load any plugins it finds.

  • --debug: Enable debug logging.

  • --input-filter <filter>: Filter the input plugins to be enabled, separated by colons.

  • --output-filter <filter>: Filter the output plug-ins to be enabled, separated by colons.

  • --pidfile <file>: Specifies the file to which the process ID is written.

  • --pprof-addr <address>: Specifies the address to listen for pprof. If empty, pprof is not activated.

  • --processor-filter <filter>: Filter the processors to be enabled, separated by colons.

  • --quiet: Runs in silent mode.

  • --section-filter: Filter the portion of the configuration to be output, valid values include 'agents', 'global_tags', 'outputs', 'processors', 'aggregators' and 'inputs'.

  • --sample-config: Prints the complete sample configuration.

  • --test: Collects metrics, prints them, and exits; no processors, aggregators, or outputs are run in test mode.

  • --test-wait: How long to wait in test mode to complete service entry.

  • --usage <plugin>: Print usage information for a specific plugin, e.g. 'telegraf --usage mysql'.

typical example

  • Generating a Telegraf Configuration Filetelegraf config >

  • Define only the configuration of the CPU input and InfluxDB output plug-instelegraf --input-filter cpu --output-filter influxdb config

  • Single Telegraf collection, output metrics to stdouttelegraf --config --test

  • Run Telegraf with all plugins defined in the configuration filetelegraf --config

  • Telegraf with CPU and memory input enabled, and InfluxDB output plugintelegraf --config --input-filter cpu:mem --output-filter influxdb

  • Telegraf with pprof runningtelegraf --config --pprof-addr localhost:6060

2.telegraf --debug debug run

The running example is as follows:

root@533b2a4c7c7d:/# telegraf --debug
2024-07-26T08:29:49Z I! Starting Telegraf 1.14.3
2024-07-26T08:29:49Z I! Using config file: /etc/telegraf/
2024-07-26T08:29:49Z I! Loaded inputs: procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat ping disk kernel mem system net cpu processes swap
2024-07-26T08:29:49Z I! Loaded aggregators:
2024-07-26T08:29:49Z I! Loaded processors:
2024-07-26T08:29:49Z I! Loaded outputs: influxdb
2024-07-26T08:29:49Z I! Tags enabled: host=controller1 nodetype=controller
2024-07-26T08:29:49Z I! [agent] Config: Interval:30s, Quiet:false, Hostname:"controller1", Flush Interval:10s
2024-07-26T08:29:49Z D! [agent] Initializing plugins
2024-07-26T08:29:49Z D! [agent] Connecting outputs
2024-07-26T08:29:49Z D! [agent] Attempting connection to []
2024-07-26T08:29:49Z W! [] When writing to [http://192.168.118.142:8097]: database "monitor" creation failed: 404 Not Found
2024-07-26T08:29:49Z D! [agent] Successfully connected to 
2024-07-26T08:29:49Z D! [agent] Starting service inputs
2024-07-26T08:30:00Z D! [] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:10Z D! [] Wrote batch of 81 metrics in 8.753274ms
2024-07-26T08:30:10Z D! [] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:20Z D! [] Wrote batch of 4 metrics in 1.620578ms
2024-07-26T08:30:20Z D! [] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:30Z D! [] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:40Z D! [] Wrote batch of 83 metrics in 11.697527ms
2024-07-26T08:30:40Z D! [] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:50Z D! [] Wrote batch of 4 metrics in 1.38142ms

Pay attention to the next few lines of the log:

  • Buffer fullnessThese messages show the status of Telegraf's internal buffers, i.e. the number of metrics waiting to be sent to InfluxDB at any given point in time. For example, "Buffer fullness: 0 / 10000 metrics" means that there are currently no metrics in the buffer waiting to be sent, while "Buffer fullness: 3 / 10000 metrics " means that there are 3 metrics in the buffer waiting to be sent. This number shows the current occupancy of the buffer compared to the total capacity of the buffer (in this case 10,000 metrics).

  • Wrote batch of X metrics in Y ms:: These messages indicate that Telegraf successfully sent a batch of metrics to InfluxDB and give the time it took to process the batch. For example, "Wrote batch of 80 metrics in 8.915386ms" means that Telegraf successfully sent 80 metrics as a batch to InfluxDB, and the process took about 8.92 milliseconds.

3. Enable debug mode by modifying the configuration file:

Modify debug to true in the configuration file