In this section, we will install Fluent Bit on a Windows machine to read logs from a file, parse the logs to extract relevant fields, and forward them to an Elasticsearch running on an Ubuntu machine.
Fluent Bit
Fluent Bit is a lightweight and high-performance log processor and forwarder. It is commonly used to collect, process, and ship logs to various destinations, such as Elasticsearch.
Installing and Configuring Fluent Bit on Windows
Download it from the official website, download the appropriate file for your Windows machine.
Extract the contents of the ZIP file to C:\Program Files\fluent-bit
Now, let's take a look at the sample logs file we want to parse
We will use Rubular to ensure the appropriate regex pattern
There is an unmatched line. Looking closely, this happened because that log has some unique attributes: TYPECODEID ,We can make another regex pattern to match it.
Now we will update the parsers.conf file, which located at C:\Program Files\Fluent-bit\conf , to add the two parsers we made previously
If you don't have permission to save changes in the file in that path, you can save it in another path, delete the unupdated one, and move the updated file after to replace it.
Next we will update the fluent-bit.conf , which is located at the same previous path. But before we start editing, we need to know the 3 main sections we will focus on.
[INPUT]: Specifies where logs are collected from; in our case, it will be collected from the sample logs file we have created.
[OUTPUT]: Specifies where logs should be sent; we want to forward them to Elasticsearch.
[PARSER]: Defines how logs should be structured using regex; we have updated the parser.conf file so there is no need to change it.
The input name tail is an input plugin that allows to monitor one or several text files. It has a similar behavior to the tail -f shell command.
The plugin reads every matched file in the Path pattern and for every new line found (separated by a newline character (\n) ), so we will duplicate some logs in the file to generate new records
Wehave configured two outputs: es is the Elasticsearch and stdout will prints to our running shell
tls : on , tls.verify : off Those are important if Elasticsearch is configured with https
Now we will run the Fluent-bit
The & operator tells PowerShell explicitly to treat the string as an executable
Open Elasticsearch and navigate to index management to ensure the existence of fluent-bit
Start to duplicate some data in the network_sample.txt, then go to discover in Elasticsearch and create a data view to the fluent-bit
We're done! Fluent Bit reads some logs, parses them using regex, and forwards the structured data to Elasticsearch.