2016-01-29 18:30:35 +00:00
# Exec Input Plugin
2015-08-20 20:40:23 +00:00
2016-03-15 13:29:05 +00:00
Please also see: [Telegraf Input Data Formats ](https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md )
2016-02-01 03:43:38 +00:00
2016-03-15 13:29:05 +00:00
### Example 1 - JSON
2015-08-20 20:40:23 +00:00
2016-03-15 13:29:05 +00:00
#### Configuration
2016-01-29 18:30:35 +00:00
2016-05-02 18:07:17 +00:00
In this example a script called ```/tmp/test.sh``` and a script called ```/tmp/test2.sh```
are configured for ```[[inputs.exec]]``` in JSON format.
2015-08-20 20:40:23 +00:00
```
2016-01-29 18:30:35 +00:00
# Read flattened metrics from one or more commands that output JSON to stdout
2016-01-14 23:55:53 +00:00
[[inputs.exec]]
2016-05-02 18:07:17 +00:00
# Shell/commands array
commands = ["/tmp/test.sh", "/tmp/test2.sh"]
2016-01-29 18:30:35 +00:00
2016-05-02 18:07:17 +00:00
# Data format to consume.
# NOTE json only reads numerical measurements, strings and booleans are ignored.
data_format = "json"
2016-01-29 18:30:35 +00:00
2016-05-02 18:07:17 +00:00
# measurement name suffix (for separating different commands)
2016-01-14 23:55:53 +00:00
name_suffix = "_mycollector"
2016-02-01 03:43:38 +00:00
2016-02-18 21:26:51 +00:00
## Below configuration will be used for data_format = "graphite", can be ignored for other data_format
## If matching multiple measurement files, this string will be used to join the matched values.
2016-02-01 03:43:38 +00:00
#separator = "."
2016-02-18 21:26:51 +00:00
## Each template line requires a template pattern. It can have an optional
## filter before the template and separated by spaces. It can also have optional extra
## tags following the template. Multiple tags should be separated by commas and no spaces
## similar to the line protocol format. The can be only one default template.
## Templates support below format:
## 1. filter + template
## 2. filter + template + extra tag
## 3. filter + template with field key
## 4. default template
2016-02-01 03:43:38 +00:00
#templates = [
# "*.app env.service.resource.measurement",
# "stats.* .host.measurement* region=us-west,agent=sensu",
# "stats2.* .host.measurement.field",
# "measurement*"
#]
2015-08-20 20:40:23 +00:00
```
2016-01-29 18:30:35 +00:00
Other options for modifying the measurement names are:
2015-09-23 18:21:42 +00:00
2016-01-29 18:30:35 +00:00
```
name_prefix = "prefix_"
```
2015-10-13 17:50:42 +00:00
2016-01-29 18:30:35 +00:00
Let's say that we have the above configuration, and mycollector outputs the
following JSON:
2015-10-13 17:50:42 +00:00
```json
{
"a": 0.5,
"b": {
2016-01-15 22:48:45 +00:00
"c": 0.1,
"d": 5
2015-10-13 17:50:42 +00:00
}
}
```
2016-01-29 18:30:35 +00:00
The collected metrics will be stored as fields under the measurement
"exec_mycollector":
2015-10-13 17:50:42 +00:00
```
2016-01-29 18:30:35 +00:00
exec_mycollector a=0.5,b_c=0.1,b_d=5 1452815002357578567
2016-01-15 22:48:45 +00:00
```
2016-03-15 13:29:05 +00:00
If using JSON, only numeric values are parsed and turned into floats. Booleans
and strings will be ignored.
### Example 2 - Influx Line-Protocol
2016-01-15 22:48:45 +00:00
2016-03-15 13:29:05 +00:00
In this example an application called ```/usr/bin/line_protocol_collector```
2016-04-05 20:42:20 +00:00
and a script called ```/tmp/test2.sh``` are configured for ```[[inputs.exec]]```
2016-03-15 13:29:05 +00:00
in influx line-protocol format.
2016-01-29 18:30:35 +00:00
2016-03-15 13:29:05 +00:00
#### Configuration
2016-01-29 18:30:35 +00:00
2016-01-15 22:48:45 +00:00
```
2016-01-29 18:30:35 +00:00
[[inputs.exec]]
2016-02-01 03:43:38 +00:00
# Shell/commands array
# compatible with old version
# we can still use the old command configuration
# command = "/usr/bin/line_protocol_collector"
commands = ["/usr/bin/line_protocol_collector","/tmp/test2.sh"]
2016-01-29 18:30:35 +00:00
2016-04-05 20:42:20 +00:00
# Data format to consume.
2016-01-29 18:30:35 +00:00
# NOTE json only reads numerical measurements, strings and booleans are ignored.
data_format = "influx"
2015-10-13 17:50:42 +00:00
```
2016-01-29 18:30:35 +00:00
2016-03-15 13:29:05 +00:00
The line_protocol_collector application outputs the following line protocol:
2016-01-29 18:30:35 +00:00
```
cpu,cpu=cpu0,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
cpu,cpu=cpu1,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
cpu,cpu=cpu2,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
cpu,cpu=cpu3,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
cpu,cpu=cpu4,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
cpu,cpu=cpu5,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
cpu,cpu=cpu6,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
```
You will get data in InfluxDB exactly as it is defined above,
tags are cpu=cpuN, host=foo, and datacenter=us-east with fields usage_idle
2016-04-05 20:42:20 +00:00
and usage_busy. They will receive a timestamp at collection time.
2016-03-15 13:29:05 +00:00
Each line must end in \n, just as the Influx line protocol does.
2016-02-01 03:43:38 +00:00
2016-03-15 13:29:05 +00:00
### Example 3 - Graphite
2016-02-01 03:43:38 +00:00
We can also change the data_format to "graphite" to use the metrics collecting scripts such as (compatible with graphite):
2016-04-05 20:42:20 +00:00
* Nagios [Metrics Plugins ](https://exchange.nagios.org/directory/Plugins )
* Sensu [Metrics Plugins ](https://github.com/sensu-plugins )
2016-02-01 03:43:38 +00:00
2016-03-15 13:29:05 +00:00
In this example a script called /tmp/test.sh and a script called /tmp/test2.sh are configured for [[inputs.exec]] in graphite format.
2016-02-01 03:43:38 +00:00
#### Configuration
```
# Read flattened metrics from one or more commands that output JSON to stdout
[[inputs.exec]]
# Shell/commands array
commands = ["/tmp/test.sh","/tmp/test2.sh"]
2016-04-05 20:42:20 +00:00
# Data format to consume.
2016-02-01 03:43:38 +00:00
# NOTE json only reads numerical measurements, strings and booleans are ignored.
data_format = "graphite"
# measurement name suffix (for separating different commands)
name_suffix = "_mycollector"
2016-02-18 21:26:51 +00:00
## Below configuration will be used for data_format = "graphite", can be ignored for other data_format
## If matching multiple measurement files, this string will be used to join the matched values.
2016-02-01 03:43:38 +00:00
separator = "."
2016-02-18 21:26:51 +00:00
## Each template line requires a template pattern. It can have an optional
## filter before the template and separated by spaces. It can also have optional extra
## tags following the template. Multiple tags should be separated by commas and no spaces
## similar to the line protocol format. The can be only one default template.
## Templates support below format:
## 1. filter + template
## 2. filter + template + extra tag
## 3. filter + template with field key
## 4. default template
2016-02-01 03:43:38 +00:00
templates = [
"*.app env.service.resource.measurement",
"stats.* .host.measurement* region=us-west,agent=sensu",
"stats2.* .host.measurement.field",
"measurement*"
]
```
2016-03-15 13:29:05 +00:00
Graphite messages are in this format:
```
metric_path value timestamp\n
```
__metric_path__ is the metric namespace that you want to populate.
__value__ is the value that you want to assign to the metric at this time.
__timestamp__ is the unix epoch time.
2016-02-01 03:43:38 +00:00
And test.sh/test2.sh will output:
```
sensu.metric.net.server0.eth0.rx_packets 461295119435 1444234982
sensu.metric.net.server0.eth0.tx_bytes 1093086493388480 1444234982
sensu.metric.net.server0.eth0.rx_bytes 1015633926034834 1444234982
sensu.metric.net.server0.eth0.tx_errors 0 1444234982
sensu.metric.net.server0.eth0.rx_errors 0 1444234982
sensu.metric.net.server0.eth0.tx_dropped 0 1444234982
sensu.metric.net.server0.eth0.rx_dropped 0 1444234982
```
The templates configuration will be used to parse the graphite metrics to support influxdb/opentsdb tagging store engines.
2016-04-05 20:42:20 +00:00
More detail information about templates, please refer to [The graphite Input ](https://github.com/influxdata/influxdb/blob/master/services/graphite/README.md )
2016-05-02 18:07:17 +00:00