1
- # Exec Plugin
1
+ # Exec Input Plugin
2
2
3
- The exec plugin can execute arbitrary commands which output JSON. Then it flattens JSON and finds
4
- all numeric values, treating them as floats .
3
+ The exec plugin can execute arbitrary commands which output JSON or
4
+ InfluxDB [ line-protocol ] ( https://docs.influxdata.com/influxdb/v0.9/write_protocols/line/ ) .
5
5
6
- For example, if you have a json-returning command called mycollector, you could
7
- setup the exec plugin with:
6
+ If using JSON, only numeric values are parsed and turned into floats. Booleans
7
+ and strings will be ignored.
8
+
9
+ ### Configuration
8
10
9
11
```
12
+ # Read flattened metrics from one or more commands that output JSON to stdout
10
13
[[inputs.exec]]
11
- command = "/usr/bin/mycollector --output=json"
14
+ # the command to run
15
+ command = "/usr/bin/mycollector --foo=bar"
16
+
17
+ # Data format to consume. This can be "json" or "influx" (line-protocol)
18
+ # NOTE json only reads numerical measurements, strings and booleans are ignored.
19
+ data_format = "json"
20
+
21
+ # measurement name suffix (for separating different commands)
12
22
name_suffix = "_mycollector"
13
- interval = "10s"
14
23
```
15
24
16
- The name suffix is appended to exec as "exec_name_suffix" to identify the input stream.
25
+ Other options for modifying the measurement names are:
17
26
18
- The interval is used to determine how often a particular command should be run. Each
19
- time the exec plugin runs, it will only run a particular command if it has been at least
20
- ` interval ` seconds since the exec plugin last ran the command.
27
+ ```
28
+ name_override = "measurement_name"
29
+ name_prefix = "prefix_"
30
+ ```
21
31
32
+ ### Example 1
22
33
23
- # Sample
34
+ Let's say that we have the above configuration, and mycollector outputs the
35
+ following JSON:
24
36
25
- Let's say that we have a command with the name_suffix "_ mycollector", which gives the following output:
26
37
``` json
27
38
{
28
39
"a" : 0.5 ,
@@ -33,13 +44,39 @@ Let's say that we have a command with the name_suffix "_mycollector", which give
33
44
}
34
45
```
35
46
36
- The collected metrics will be stored as field values under the same measurement "exec_mycollector":
47
+ The collected metrics will be stored as fields under the measurement
48
+ "exec_mycollector":
49
+
37
50
```
38
- exec_mycollector a=0.5,b_c=0.1,b_d=5 1452815002357578567
51
+ exec_mycollector a=0.5,b_c=0.1,b_d=5 1452815002357578567
39
52
```
40
53
41
- Other options for modifying the measurement names are:
54
+ ### Example 2
55
+
56
+ Now let's say we have the following configuration:
57
+
42
58
```
43
- name_override = "newname"
44
- name_prefix = "prefix_"
59
+ [[inputs.exec]]
60
+ # the command to run
61
+ command = "/usr/bin/line_protocol_collector"
62
+
63
+ # Data format to consume. This can be "json" or "influx" (line-protocol)
64
+ # NOTE json only reads numerical measurements, strings and booleans are ignored.
65
+ data_format = "influx"
45
66
```
67
+
68
+ And line_protocol_collector outputs the following line protocol:
69
+
70
+ ```
71
+ cpu,cpu=cpu0,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
72
+ cpu,cpu=cpu1,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
73
+ cpu,cpu=cpu2,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
74
+ cpu,cpu=cpu3,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
75
+ cpu,cpu=cpu4,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
76
+ cpu,cpu=cpu5,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
77
+ cpu,cpu=cpu6,host=foo,datacenter=us-east usage_idle=99,usage_busy=1
78
+ ```
79
+
80
+ You will get data in InfluxDB exactly as it is defined above,
81
+ tags are cpu=cpuN, host=foo, and datacenter=us-east with fields usage_idle
82
+ and usage_busy. They will receive a timestamp at collection time.
0 commit comments