Skip to content

Commit 51ad5ad

Browse files
authored
Fixes for standarizing on YAML configs, shell command cleanup, and warning for copytruncate on logrotate added. Fixes #1770. (#1804)
Signed-off-by: Eric D. Schabell <[email protected]>
1 parent e99b1bc commit 51ad5ad

File tree

1 file changed

+110
-74
lines changed

1 file changed

+110
-74
lines changed

pipeline/inputs/tail.md

Lines changed: 110 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,40 @@ Replace _`LIMIT1`_ and _`LIMIT2`_ with the integer values of your choosing. High
5656
However, these changes revert upon reboot unless you write them to the appropriate `inotify.conf` file, in which case they will persist across reboots. The specific name of this file might vary depending on how you built and installed Fluent Bit. For example, to write changes to a file named `fluent-bit_fs_inotify.conf`, run the following commands:
5757

5858
```shell
59-
mkdir -p /etc/sysctl.d
60-
echo fs.inotify.max_user_watches = LIMIT1 >> /etc/sysctl.d/fluent-bit_fs_inotify.conf
61-
echo fs.inotify.max_user_instances = LIMIT2 >> /etc/sysctl.d/fluent-bit_fs_inotify.conf
59+
$ mkdir -p /etc/sysctl.d
60+
$ echo fs.inotify.max_user_watches = LIMIT1 >> /etc/sysctl.d/fluent-bit_fs_inotify.conf
61+
$ echo fs.inotify.max_user_instances = LIMIT2 >> /etc/sysctl.d/fluent-bit_fs_inotify.conf
6262
```
6363

6464
Replace _`LIMIT1`_ and _`LIMIT2`_ with the integer values of your choosing.
6565

66-
You can also provide a custom systemd configuration file that overrides the default systemd settings for Fluent Bit. This override file must be located at `/etc/systemd/system/fluent-bit.service.d/override.conf`. For example, you can add this snippet to your override file to raise the number of files that the Tail plugin can monitor:
66+
You can also provide a custom systemd configuration file that overrides the default systemd settings for Fluent Bit. This override file must be located at `/etc/systemd/system/fluent-bit.service.d/override.conf` or `/etc/systemd/system/fluent-bit.service.d/override.yaml` depending
67+
on the configuration you choose. For example, you can add one of these snippets to your override file to raise the number of files that the Tail plugin can monitor:
68+
{% tabs %}
69+
{% tab title="override.yaml" %}
70+
71+
```yaml
72+
service:
73+
limitnofile: LIMIT
74+
```
75+
76+
{% endtab %}
77+
{% tab title="override.conf" %}
6778
6879
```text
6980
[Service]
7081
LimitNOFILE=LIMIT
7182
```
7283

84+
{% endtab %}
85+
{% endtabs %}
86+
7387
Replace _`LIMIT`_ with the integer value of your choosing.
7488

7589
If you don't already have an override file, you can use the following command to create one in the correct directory:
7690

77-
```shell copy
78-
systemctl edit fluent-bit.service
91+
```shell
92+
$ systemctl edit fluent-bit.service
7993
```
8094

8195
## Multiline Support
@@ -107,23 +121,26 @@ As stated in the [Multiline Parser documentation](../../administration/configuri
107121
If you are running Fluent Bit to process logs coming from containers like Docker or CRI, you can use the new built-in modes for such purposes. This will help to reassembly multiline messages originally split by Docker or CRI:
108122

109123
{% tabs %}
124+
{% tab title="fluent-bit.yaml" %}
125+
126+
```yaml
127+
pipeline:
128+
inputs:
129+
- name: tail
130+
path: /var/log/containers/*.log
131+
multiline.parser: docker, cri
132+
```
133+
134+
{% endtab %}
110135
{% tab title="fluent-bit.conf" %}
136+
111137
```text
112138
[INPUT]
113139
name tail
114140
path /var/log/containers/*.log
115141
multiline.parser docker, cri
116142
```
117-
{% endtab %}
118143

119-
{% tab title="fluent-bit.yaml" %}
120-
```yaml
121-
pipeline:
122-
inputs:
123-
- name: tail
124-
path: /var/log/containers/*.log
125-
multiline.parser: docker, cri
126-
```
127144
{% endtab %}
128145
{% endtabs %}
129146

@@ -164,16 +181,31 @@ In order to tail text or log files, you can run the plugin from the command line
164181

165182
From the command line you can let Fluent Bit parse text files with the following options:
166183

167-
```bash
184+
```shell
168185
$ fluent-bit -i tail -p path=/var/log/syslog -o stdout
169186
```
170187

171188
### Configuration File
172189

173-
In your main configuration file, append the following `Input` and `Output` sections:
190+
Append the following in your main configuration file:
174191

175192
{% tabs %}
193+
{% tab title="fluent-bit.yaml" %}
194+
195+
```yaml
196+
pipeline:
197+
inputs:
198+
- name: tail
199+
path: /var/log/syslog
200+
201+
outputs:
202+
- stdout:
203+
match: *
204+
```
205+
206+
{% endtab %}
176207
{% tab title="fluent-bit.conf" %}
208+
177209
```text
178210
[INPUT]
179211
Name tail
@@ -183,24 +215,10 @@ In your main configuration file, append the following `Input` and `Output` secti
183215
Name stdout
184216
Match *
185217
```
186-
{% endtab %}
187-
188-
{% tab title="fluent-bit.yaml" %}
189-
```yaml
190-
pipeline:
191-
inputs:
192-
- name: tail
193-
path: /var/log/syslog
194218

195-
outputs:
196-
- stdout:
197-
match: *
198-
```
199219
{% endtab %}
200220
{% endtabs %}
201221

202-
![](../../.gitbook/assets/image%20%286%29.png)
203-
204222
### Old Multi-line example
205223

206224
When using multi-line configuration you need to first specify `Multiline On` in the configuration and use the `Parser_Firstline` and additional parser parameters `Parser_N` if needed. If we are trying to read the following Java Stacktrace as a single event
@@ -220,7 +238,20 @@ In the case above we can use the following parser, that extracts the Time as `ti
220238

221239

222240
{% tabs %}
241+
{% tab title="fluent-bit.yaml" %}
242+
243+
```yaml
244+
parsers:
245+
- name: multiline
246+
format: regex
247+
regex: '/(?<time>[A-Za-z]+ \d+ \d+\:\d+\:\d+)(?<message>.*)/'
248+
time_key: time
249+
time_format: '%b %d %H:%M:%S'
250+
```
251+
252+
{% endtab %}
223253
{% tab title="fluent-bit.conf" %}
254+
224255
```text
225256
[PARSER]
226257
Name multiline
@@ -229,24 +260,39 @@ In the case above we can use the following parser, that extracts the Time as `ti
229260
Time_Key time
230261
Time_Format %b %d %H:%M:%S
231262
```
232-
{% endtab %}
233263

234-
{% tab title="fluent-bit.yaml" %}
235-
```yaml
236-
parsers:
237-
- name: multiline
238-
format: regex
239-
regex: '/(?<time>[A-Za-z]+ \d+ \d+\:\d+\:\d+)(?<message>.*)/'
240-
time_key: time
241-
time_format: '%b %d %H:%M:%S'
242-
```
243264
{% endtab %}
244265
{% endtabs %}
245266

246267
If we want to further parse the entire event we can add additional parsers with `Parser_N` where N is an integer. The final Fluent Bit configuration looks like the following:
247268

248269
{% tabs %}
270+
{% tab title="fluent-bit.yaml" %}
271+
272+
```yaml
273+
parsers:
274+
- name: multiline
275+
format: regex
276+
regex: '/(?<time>[A-Za-z]+ \d+ \d+\:\d+\:\d+)(?<message>.*)/'
277+
time_key: time
278+
time_format: '%b %d %H:%M:%S'
279+
280+
pipeline:
281+
inputs:
282+
- name: tail
283+
multiline: on
284+
read_from_head: true
285+
parser_firstline: multiline
286+
path: /var/log/java.log
287+
288+
outputs:
289+
- name: stdout
290+
match: '*'
291+
```
292+
293+
{% endtab %}
249294
{% tab title="fluent-bit.conf" %}
295+
250296
```text
251297
# Note this is generally added to parsers.conf and referenced in [SERVICE]
252298
[PARSER]
@@ -266,29 +312,7 @@ If we want to further parse the entire event we can add additional parsers with
266312
Name stdout
267313
Match *
268314
```
269-
{% endtab %}
270315

271-
{% tab title="fluent-bit.yaml" %}
272-
```yaml
273-
parsers:
274-
- name: multiline
275-
format: regex
276-
regex: '/(?<time>[A-Za-z]+ \d+ \d+\:\d+\:\d+)(?<message>.*)/'
277-
time_key: time
278-
time_format: '%b %d %H:%M:%S'
279-
280-
pipeline:
281-
inputs:
282-
- name: tail
283-
multiline: on
284-
read_from_head: true
285-
parser_firstline: multiline
286-
path: /var/log/java.log
287-
288-
outputs:
289-
- name: stdout
290-
match: '*'
291-
```
292316
{% endtab %}
293317
{% endtabs %}
294318

@@ -306,7 +330,7 @@ Our output will be as follows.
306330

307331
The _tail_ input plugin a feature to save the state of the tracked files, is strongly suggested you enabled this. For this purpose the **db** property is available, e.g:
308332

309-
```bash
333+
```shell
310334
$ fluent-bit -i tail -p path=/var/log/syslog -p db=/path/to/logs.db -o stdout
311335
```
312336

@@ -344,23 +368,26 @@ Fluent Bit keep the state or checkpoint of each file through using a SQLite data
344368
The SQLite journaling mode enabled is `Write Ahead Log` or `WAL`. This allows to improve performance of read and write operations to disk. When enabled, you will see in your file system additional files being created, consider the following configuration statement:
345369

346370
{% tabs %}
371+
{% tab title="fluent-bit.yaml" %}
372+
373+
```yaml
374+
pipeline:
375+
inputs:
376+
- name: tail
377+
path: /var/log/containers/*.log
378+
db: test.db
379+
```
380+
381+
{% endtab %}
347382
{% tab title="fluent-bit.conf" %}
383+
348384
```text
349385
[INPUT]
350386
name tail
351387
path /var/log/containers/*.log
352388
db test.db
353389
```
354-
{% endtab %}
355390

356-
{% tab title="fluent-bit.yaml" %}
357-
```yaml
358-
pipeline:
359-
inputs:
360-
- name: tail
361-
path: /var/log/containers/*.log
362-
db: test.db
363-
```
364391
{% endtab %}
365392
{% endtabs %}
366393

@@ -379,4 +406,13 @@ The `WAL` mechanism give us higher performance but also might increase the memor
379406

380407
File rotation is properly handled, including logrotate's _copytruncate_ mode.
381408

382-
Note that the `Path` patterns **cannot** match the rotated files. Otherwise, the rotated file would be read again and lead to duplicate records.
409+
{% hint style="warning" %}
410+
411+
Note that while file rotation is handled, there are risks of potential log loss when using `logrotate` with `copytruncate` mode:
412+
413+
- race conditions: logs can be lost in the brief window between copying and truncating the file.
414+
- backpressure: if Fluent Bit is under backpressure, logs might be dropped if `copyttruncate` occurs before they can be processed and sent.
415+
- see `logroate man page`: "Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost."
416+
- final note: the `Path` patterns **cannot** match the rotated files. Otherwise, the rotated file would be read again and lead to duplicate records.
417+
418+
{% endhint %}

0 commit comments

Comments
 (0)