Fluentd
Search…
exec
The in_exec Input plugin executes external programs to receive or pull event logs. It will then read TSV (tab-separated values), JSON or MessagePack from the standard output of the program.
You can run a program periodically or permanently. To run periodically, please use the run_interval parameter.
It is included in Fluentd's core.

Example Configuration

1
<source>
2
@type exec
3
command cmd arg arg
4
<parse>
5
keys k1,k2,k3
6
</parse>
7
<extract>
8
tag_key k1
9
time_key k2
10
time_format %Y-%m-%d %H:%M:%S
11
</extract>
12
run_interval 10s
13
</source>
Copied!
Refer to the Configuration File article for the basic structure and syntax of the configuration file.

Plugin Helpers

Parameters

@type

The value must be exec.

command

type
default
version
string
required parameter
0.14.0
The command (program) to execute.

tag

type
default
version
string
required if extract/tag_key is not specified
0.14.0
The tag of the output events.

run_interval

type
default
version
time
nil
0.14.0
The interval time between periodic program runs. If not specified, command script runs only once.

read_block_size

type
default
version
size
10240
0.14.9
The default block size to read if parser requires partial read.

connect_mode

type
default
available values
version
enum
read
read/read_with_stderr
1.11.3
Control target IO:
    read: Read logs from stdio
    read_with_stderr: Read logs from stdio and stderr.
read_with_stderr is mainly for debug.

<parse> section

required
multi
version
false
false
0.14.9
Refer these for more details about parse section:

@type

type
default
version
string
tsv
0.14.9
Overwrites the default value in this plugin.

time_type

type
default
version
string
float
0.14.9
Overwrites the default value in this plugin.

time_key

type
default
version
string
nil
0.14.9
Overwrites the default value in this plugin.

estimate_current_event

type
default
version
bool
false
0.14.9
Overwrites the default value in this plugin.

<extract> Section

required
multi
version
false
false
0.14.9

time_type

type
default
version
string
float
0.14.9
Overwrites the default value in this plugin.

Use Cases

Monitor Load Averages

Here is a simple example to fetch load average stats on Linux systems. This configuration instructs Fluentd to read /proc/loadavg once per minute and emit the file content as events.
1
<source>
2
@type exec
3
tag system.loadavg
4
command cat /proc/loadavg | cut -d ' ' -f 1,2,3
5
run_interval 1m
6
<parse>
7
@type tsv
8
keys avg1,avg5,avg15
9
delimiter " "
10
</parse>
11
</source>
Copied!
This configuration emits events like this one:
1
2018-06-29 17:27:35.115878527 +0900 system.loadavg: {"avg1":"0.30","avg5":"0.20","avg15":"0.05"}
Copied!

Real World Example: Scrape Hacker News Top Page

If you already have a script that runs periodically (say, via cron) that you wish to store the output to multiple backend systems (HDFS, AWS, Elasticsearch, etc.), in_exec is a great choice.
The only requirement for the script is that it outputs TSV, JSON or MessagePack.
For example, this script scrapes the front page of Hacker News and scrapes information about each post:
Suppose that script is called hn.rb. Then, you can run it every 5 minutes with the following configuration:
1
<source>
2
@type exec
3
<parse>
4
@type json
5
</parse>
6
tag hackernews
7
command ruby /path/to/hn.rb
8
run_interval 5m # don't hit HN too frequently!
9
</source>
10
<match hackernews>
11
@type stdout
12
</match>
Copied!
And if you run Fluentd with it, you will see the following output (if you are impatient, CTRL+C to flush the stdout buffer):
1
2017-12-08 14:19:33.160567411 +0900 hackernews: {"time":1512710373,"rank":1,"title":"Japan eyes startup visa program","points":160,"user_name":"benguild","duration":"4 hours ago ","num_comments":0,"unique_id":"item?id=15875627","hiring_notice":false}
2
2017-12-08 14:19:33.160735378 +0900 hackernews: {"time":1512710373,"rank":2,"title":"Bookbinding: A Tutorial","points":46,"user_name":"jstrieb","duration":"2 hours ago ","num_comments":0,"unique_id":"item?id=15876260","hiring_notice":false}
3
2017-12-08 14:19:33.160769125 +0900 hackernews: {"time":1512710373,"rank":3,"title":"My Quadriplegic Husband and Me","points":92,"user_name":"mooreds","duration":"4 hours ago ","num_comments":0,"unique_id":"item?id=15875772","hiring_notice":false}
4
2017-12-08 14:19:33.160799115 +0900 hackernews: {"time":1512710373,"rank":4,"title":"Wall Street banks hit pause button on Bitcoin","points":16,"user_name":"tadasv","duration":"1 hour ago ","num_comments":0,"unique_id":"item?id=15876497","hiring_notice":false}
5
2017-12-08 14:19:33.160824386 +0900 hackernews: {"time":1512710373,"rank":5,"title":"A Spectator Who Threw a Wrench in the Waymo/Uber Lawsuit","points":107,"user_name":"kynthelig","duration":"4 hours ago ","num_comments":0,"unique_id":"item?id=15875685","hiring_notice":false}
Copied!
Of course, you can use Fluentd's many output plugins to store the data into various backend systems like Elasticsearch, HDFS, MongoDB, AWS, etc.
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is an open-source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.
Last modified 4mo ago