2016-01-29 18:30:35 +00:00
|
|
|
# Exec Input Plugin
|
2015-08-20 20:40:23 +00:00
|
|
|
|
2016-01-29 18:30:35 +00:00
|
|
|
The exec plugin can execute arbitrary commands which output JSON or
|
|
|
|
InfluxDB [line-protocol](https://docs.influxdata.com/influxdb/v0.9/write_protocols/line/).
|
2015-08-20 20:40:23 +00:00
|
|
|
|
2016-01-29 18:30:35 +00:00
|
|
|
If using JSON, only numeric values are parsed and turned into floats. Booleans
|
|
|
|
and strings will be ignored.
|
|
|
|
|
|
|
|
### Configuration
|
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-01-29 18:30:35 +00:00
|
|
|
# the command to run
|
|
|
|
command = "/usr/bin/mycollector --foo=bar"
|
|
|
|
|
|
|
|
# Data format to consume. This can be "json" or "influx" (line-protocol)
|
|
|
|
# NOTE json only reads numerical measurements, strings and booleans are ignored.
|
|
|
|
data_format = "json"
|
|
|
|
|
|
|
|
# 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
|
|
|
```
|
|
|
|
|
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_override = "measurement_name"
|
|
|
|
name_prefix = "prefix_"
|
|
|
|
```
|
2015-10-13 17:50:42 +00:00
|
|
|
|
2016-01-29 18:30:35 +00:00
|
|
|
### Example 1
|
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-01-29 18:30:35 +00:00
|
|
|
### Example 2
|
|
|
|
|
|
|
|
Now let's say we have the following configuration:
|
|
|
|
|
2016-01-15 22:48:45 +00:00
|
|
|
```
|
2016-01-29 18:30:35 +00:00
|
|
|
[[inputs.exec]]
|
|
|
|
# the command to run
|
|
|
|
command = "/usr/bin/line_protocol_collector"
|
|
|
|
|
|
|
|
# Data format to consume. This can be "json" or "influx" (line-protocol)
|
|
|
|
# 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
|
|
|
|
|
|
|
And line_protocol_collector outputs the following line protocol:
|
|
|
|
|
|
|
|
```
|
|
|
|
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
|
|
|
|
and usage_busy. They will receive a timestamp at collection time.
|