telegraf/plugins/inputs/exec/README.md

58 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

# Exec Input Plugin
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).
2017-12-12 01:58:06 +00:00
This plugin can be used to poll for custom metrics from any source.
2017-12-12 01:58:06 +00:00
### Configuration:
```toml
[[inputs.exec]]
2017-12-12 01:58:06 +00:00
## Commands array
commands = [
"/tmp/test.sh",
"/usr/bin/mycollector --foo=bar",
"/tmp/collect_*.sh"
]
## Timeout for each command to complete.
timeout = "5s"
2017-12-12 01:58:06 +00:00
## measurement name suffix (for separating different commands)
name_suffix = "_mycollector"
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"
```
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.
2017-12-12 01:58:06 +00:00
### Example:
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'
```
2017-12-12 01:58:06 +00:00
It can be paired with the following configuration and will be ran at the `interval` of the agent.
```toml
[[inputs.exec]]
2017-12-12 01:58:06 +00:00
commands = ["sh /tmp/test.sh"]
timeout = "5s"
data_format = "influx"
```
2017-12-12 01:58:06 +00:00
### Common Issues:
2017-12-12 01:58:06 +00:00
#### Q: My script works when I run it by hand, but not when Telegraf is running as a service.
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.