Head
The head input plugin, allows to read events from the head of file. It's behavior is similar to the head command.

Configuration Parameters

The plugin supports the following configuration parameters:
Key
Description
File
Absolute path to the target file, e.g: /proc/uptime
Buf_Size
Buffer size to read the file.
Interval_Sec
Polling interval (seconds).
Interval_NSec
Polling interval (nanosecond).
Add_Path
If enabled, filepath is appended to each records. Default value is false.
Key
Rename a key. Default: head.
Lines
Line number to read. If the number N is set, in_head reads first N lines like head(1) -n.
Split_line
If enabled, in_head generates key-value pair per line.

Split Line Mode

This mode is useful to get a specific line. This is an example to get CPU frequency from /proc/cpuinfo.
/proc/cpuinfo is a special file to get cpu information.
1
processor : 0
2
vendor_id : GenuineIntel
3
cpu family : 6
4
model : 42
5
model name : Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz
6
stepping : 7
7
microcode : 41
8
cpu MHz : 2791.009
9
cache size : 4096 KB
10
physical id : 0
11
siblings : 1
Copied!
Cpu frequency is "cpu MHz : 2791.009". We can get the line with this configuration file.
1
[INPUT]
2
Name head
3
Tag head.cpu
4
File /proc/cpuinfo
5
Lines 8
6
Split_line true
7
# {"line0":"processor : 0", "line1":"vendor_id : GenuineIntel" ...}
8
9
[FILTER]
10
Name record_modifier
11
Match *
12
Whitelist_key line7
13
14
[OUTPUT]
15
Name stdout
16
Match *
Copied!
Output is
1
$ bin/fluent-bit -c head.conf
2
Fluent Bit v1.x.x
3
* Copyright (C) 2019-2020 The Fluent Bit Authors
4
* Copyright (C) 2015-2018 Treasure Data
5
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
6
* https://fluentbit.io
7
8
[2017/06/26 22:38:24] [ info] [engine] started
9
[0] head.cpu: [1498484305.000279805, {"line7"=>"cpu MHz : 2791.009"}]
10
[1] head.cpu: [1498484306.011680137, {"line7"=>"cpu MHz : 2791.009"}]
11
[2] head.cpu: [1498484307.010042482, {"line7"=>"cpu MHz : 2791.009"}]
12
[3] head.cpu: [1498484308.008447978, {"line7"=>"cpu MHz : 2791.009"}]
Copied!

Getting Started

In order to read the head of a file, you can run the plugin from the command line or through the configuration file:

Command Line

The following example will read events from the /proc/uptime file, tag the records with the uptime name and flush them back to the stdout plugin:
1
$ fluent-bit -i head -t uptime -p File=/proc/uptime -o stdout -m '*'
2
Fluent Bit v1.x.x
3
* Copyright (C) 2019-2020 The Fluent Bit Authors
4
* Copyright (C) 2015-2018 Treasure Data
5
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
6
* https://fluentbit.io
7
8
[2016/05/17 21:53:54] [ info] starting engine
9
[0] uptime: [1463543634, {"head"=>"133517.70 194870.97"}]
10
[1] uptime: [1463543635, {"head"=>"133518.70 194872.85"}]
11
[2] uptime: [1463543636, {"head"=>"133519.70 194876.63"}]
12
[3] uptime: [1463543637, {"head"=>"133520.70 194879.72"}]
Copied!

Configuration File

In your main configuration file append the following Input & Output sections:
1
[INPUT]
2
Name head
3
Tag uptime
4
File /proc/uptime
5
Buf_Size 256
6
Interval_Sec 1
7
Interval_NSec 0
8
9
[OUTPUT]
10
Name stdout
11
Match *
Copied!
Note: Total interval (sec) = Interval_Sec + (Interval_Nsec / 1000000000).
e.g. 1.5s = 1s + 500000000ns
Last modified 1yr ago