telegraf/plugins/inputs/exec
Josh Soref 2c56d6de81
Fix spelling errors in comments and documentation (#7492)
2020-05-14 00:41:58 -07:00
..
dev Add dev/telegraf.conf for docker, exec, and procstat input (#4460) 2018-07-27 18:39:37 -07:00
README.md Fix spelling errors in comments and documentation (#7492) 2020-05-14 00:41:58 -07:00
exec.go Fix logger initialization in exec input (#6492) 2019-10-07 12:18:36 -07:00
exec_test.go Fix logger initialization in exec input (#6492) 2019-10-07 12:18:36 -07:00

README.md

Exec Input Plugin

The exec plugin executes the commands on every interval and parses metrics from their output in any one of the accepted Input Data Formats.

This plugin can be used to poll for custom metrics from any source.

Configuration:

[[inputs.exec]]
  ## Commands array
  commands = [
    "/tmp/test.sh",
    "/usr/bin/mycollector --foo=bar",
    "/tmp/collect_*.sh"
  ]

  ## Timeout for each command to complete.
  timeout = "5s"

  ## measurement name suffix (for separating different commands)
  name_suffix = "_mycollector"

  ## Data format to consume.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
  data_format = "influx"

Glob patterns in the command option are matched on every run, so adding new scripts that match the pattern will cause them to be picked up immediately.

Example:

This script produces static values, since no timestamp is specified the values are at the current time.

#!/bin/sh
echo 'example,tag1=a,tag2=b i=42i,j=43i,k=44i'

It can be paired with the following configuration and will be run at the interval of the agent.

[[inputs.exec]]
  commands = ["sh /tmp/test.sh"]
  timeout = "5s"
  data_format = "influx"

Common Issues:

My script works when I run it by hand, but not when Telegraf is running as a service.

This may be related to the Telegraf service running as a different user. The official packages run Telegraf as the telegraf user and group on Linux systems.

With a PowerShell on Windows, the output of the script appears to be truncated.

You may need to set a variable in your script to increase the number of columns available for output:

$host.UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size(1024,50)