2016-01-30 02:30:35 +08:00
|
|
|
# Exec Input Plugin
|
2015-08-21 04:40:23 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
The `exec` plugin executes all the `commands` in parallel on every interval and
|
|
|
|
|
parses metrics from their output in any one of the accepted [Input Data
|
|
|
|
|
Formats](../../../docs/DATA_FORMATS_INPUT.md).
|
2016-02-01 11:43:38 +08:00
|
|
|
|
2017-12-12 09:58:06 +08:00
|
|
|
This plugin can be used to poll for custom metrics from any source.
|
2015-08-21 04:40:23 +08:00
|
|
|
|
2022-10-27 03:58:36 +08:00
|
|
|
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
|
|
|
|
|
|
|
|
|
In addition to the plugin-specific configuration settings, plugins support
|
|
|
|
|
additional global and plugin configuration settings. These settings are used to
|
|
|
|
|
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
|
|
|
|
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
|
|
|
|
|
|
|
|
|
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md
|
|
|
|
|
|
2021-11-25 02:56:26 +08:00
|
|
|
## Configuration
|
2015-08-21 04:40:23 +08:00
|
|
|
|
2022-05-24 21:49:47 +08:00
|
|
|
```toml @sample.conf
|
2022-04-08 06:01:21 +08:00
|
|
|
# Read metrics from one or more commands that can output to stdout
|
2016-01-15 07:55:53 +08:00
|
|
|
[[inputs.exec]]
|
2017-12-12 09:58:06 +08:00
|
|
|
## Commands array
|
|
|
|
|
commands = [
|
|
|
|
|
"/tmp/test.sh",
|
|
|
|
|
"/usr/bin/mycollector --foo=bar",
|
|
|
|
|
"/tmp/collect_*.sh"
|
|
|
|
|
]
|
2016-01-30 02:30:35 +08:00
|
|
|
|
2022-05-11 05:34:05 +08:00
|
|
|
## Environment variables
|
|
|
|
|
## Array of "key=value" pairs to pass as environment variables
|
|
|
|
|
## e.g. "KEY=value", "USERNAME=John Doe",
|
|
|
|
|
## "LD_LIBRARY_PATH=/opt/custom/lib64:/usr/local/libs"
|
|
|
|
|
# environment = []
|
|
|
|
|
|
2016-06-03 20:32:16 +08:00
|
|
|
## Timeout for each command to complete.
|
|
|
|
|
timeout = "5s"
|
|
|
|
|
|
2017-12-12 09:58:06 +08:00
|
|
|
## measurement name suffix (for separating different commands)
|
2016-01-15 07:55:53 +08:00
|
|
|
name_suffix = "_mycollector"
|
2015-08-21 04:40:23 +08:00
|
|
|
|
2017-12-12 09:58:06 +08: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-30 02:30:35 +08:00
|
|
|
```
|
2015-10-14 01:50:42 +08:00
|
|
|
|
2017-12-12 09:58:06 +08: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-14 01:50:42 +08:00
|
|
|
|
2021-11-25 02:56:26 +08:00
|
|
|
## Example
|
2016-01-30 02:30:35 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
This script produces static values, since no timestamp is specified the values
|
2022-08-03 20:42:22 +08:00
|
|
|
are at the current time. Ensure that int values are followed with `i` for proper
|
|
|
|
|
parsing.
|
2021-11-25 02:56:26 +08:00
|
|
|
|
2017-12-12 09:58:06 +08:00
|
|
|
```sh
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
echo 'example,tag1=a,tag2=b i=42i,j=43i,k=44i'
|
2015-10-14 01:50:42 +08:00
|
|
|
```
|
2016-01-30 02:30:35 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
It can be paired with the following configuration and will be run at the
|
|
|
|
|
`interval` of the agent.
|
2021-11-25 02:56:26 +08:00
|
|
|
|
2016-06-03 20:32:16 +08:00
|
|
|
```toml
|
2016-01-30 02:30:35 +08:00
|
|
|
[[inputs.exec]]
|
2017-12-12 09:58:06 +08:00
|
|
|
commands = ["sh /tmp/test.sh"]
|
2016-06-03 20:32:16 +08:00
|
|
|
timeout = "5s"
|
2016-01-30 02:30:35 +08:00
|
|
|
data_format = "influx"
|
2015-10-14 01:50:42 +08:00
|
|
|
```
|
2016-01-30 02:30:35 +08:00
|
|
|
|
2021-11-25 02:56:26 +08:00
|
|
|
## Common Issues
|
2016-02-01 11:43:38 +08:00
|
|
|
|
2021-11-25 02:56:26 +08:00
|
|
|
### My script works when I run it by hand, but not when Telegraf is running as a service
|
2016-02-01 11:43:38 +08:00
|
|
|
|
2022-05-11 05:34:05 +08:00
|
|
|
This may be related to the Telegraf service running as a different user. The
|
2017-12-12 09:58:06 +08:00
|
|
|
official packages run Telegraf as the `telegraf` user and group on Linux
|
|
|
|
|
systems.
|
2020-01-16 11:29:50 +08:00
|
|
|
|
2021-11-25 02:56:26 +08:00
|
|
|
### With a PowerShell on Windows, the output of the script appears to be truncated
|
2020-01-16 11:29:50 +08:00
|
|
|
|
2020-05-14 15:41:58 +08:00
|
|
|
You may need to set a variable in your script to increase the number of columns
|
2020-01-16 11:29:50 +08:00
|
|
|
available for output:
|
2021-11-25 02:56:26 +08:00
|
|
|
|
|
|
|
|
```shell
|
2020-01-16 11:29:50 +08:00
|
|
|
$host.UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size(1024,50)
|
|
|
|
|
```
|