2016-01-29 18:30:35 +00:00
|
|
|
# Exec Input Plugin
|
2015-08-20 20:40:23 +00:00
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
The `exec` plugin executes the `commands` on every interval and parses metrics from
|
|
|
|
their output in any one of the accepted [Input Data Formats](https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md).
|
2016-02-01 03:43:38 +00:00
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
This plugin can be used to poll for custom metrics from any source.
|
2015-08-20 20:40:23 +00:00
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
### Configuration:
|
2015-08-20 20:40:23 +00:00
|
|
|
|
2016-06-03 12:32:16 +00:00
|
|
|
```toml
|
2016-01-14 23:55:53 +00:00
|
|
|
[[inputs.exec]]
|
2017-12-12 01:58:06 +00:00
|
|
|
## Commands array
|
|
|
|
commands = [
|
|
|
|
"/tmp/test.sh",
|
|
|
|
"/usr/bin/mycollector --foo=bar",
|
|
|
|
"/tmp/collect_*.sh"
|
|
|
|
]
|
2016-01-29 18:30:35 +00:00
|
|
|
|
2016-06-03 12:32:16 +00:00
|
|
|
## Timeout for each command to complete.
|
|
|
|
timeout = "5s"
|
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
## measurement name suffix (for separating different commands)
|
2016-01-14 23:55:53 +00:00
|
|
|
name_suffix = "_mycollector"
|
2015-08-20 20:40:23 +00:00
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
## 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"
|
2016-01-29 18:30:35 +00:00
|
|
|
```
|
2015-10-13 17:50:42 +00:00
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
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.
|
2015-10-13 17:50:42 +00:00
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
### Example:
|
2016-01-29 18:30:35 +00:00
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
This script produces static values, since no timestamp is specified the values are at the current time.
|
|
|
|
```sh
|
|
|
|
#!/bin/sh
|
|
|
|
echo 'example,tag1=a,tag2=b i=42i,j=43i,k=44i'
|
2015-10-13 17:50:42 +00:00
|
|
|
```
|
2016-01-29 18:30:35 +00:00
|
|
|
|
2018-09-24 20:41:12 +00:00
|
|
|
It can be paired with the following configuration and will be run at the `interval` of the agent.
|
2016-06-03 12:32:16 +00:00
|
|
|
```toml
|
2016-01-29 18:30:35 +00:00
|
|
|
[[inputs.exec]]
|
2017-12-12 01:58:06 +00:00
|
|
|
commands = ["sh /tmp/test.sh"]
|
2016-06-03 12:32:16 +00:00
|
|
|
timeout = "5s"
|
2016-01-29 18:30:35 +00:00
|
|
|
data_format = "influx"
|
2015-10-13 17:50:42 +00:00
|
|
|
```
|
2016-01-29 18:30:35 +00:00
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
### Common Issues:
|
2016-02-01 03:43:38 +00:00
|
|
|
|
2020-01-16 03:29:50 +00:00
|
|
|
#### My script works when I run it by hand, but not when Telegraf is running as a service.
|
2016-02-01 03:43:38 +00:00
|
|
|
|
2017-12-12 01:58:06 +00:00
|
|
|
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.
|
2020-01-16 03:29:50 +00:00
|
|
|
|
|
|
|
#### With a PowerShell on Windows, the output of the script appears to be truncated.
|
|
|
|
|
2020-05-14 07:41:58 +00:00
|
|
|
You may need to set a variable in your script to increase the number of columns
|
2020-01-16 03:29:50 +00:00
|
|
|
available for output:
|
|
|
|
```
|
|
|
|
$host.UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size(1024,50)
|
|
|
|
```
|