Skip to main content

使用 Fluentbit 发送日志

Fluent Bit 是一个开源的日志和指标处理器及转发器,可转发到多个目的地。

在本指南中,我们将向您展示如何将其连接到 Quickwit。

先决条件

为 Fluentbit 日志创建一个简单的索引

让我们创建一个只有一个字段 timestamp 的无模式索引。模式 dynamic 表示 Quickwit 将索引所有字段,即使它们未在文档映射中定义。

index-config.yaml
version: 0.7

index_id: fluentbit-logs

doc_mapping:
mode: dynamic
field_mappings:
- name: timestamp
type: datetime
input_formats:
- unix_timestamp
output_format: unix_timestamp_secs
fast: true
timestamp_field: timestamp

indexing_settings:
commit_timeout_secs: 10
curl -o fluentbit-logs.yaml https://raw.githubusercontent.com/quickwit-oss/quickwit/main/config/tutorials/fluentbit-logs/index-config.yaml

然后使用 cURLCLI 创建索引:

curl -XPOST http://localhost:7280/api/v1/indexes -H "content-type: application/yaml" --data-binary @fluentbit-logs.yaml

设置 Fluentbit

Fluentbit 配置文件由输入和输出组成。对于本教程,我们将使用一个虚拟配置:

[INPUT]
Name dummy
Tag dummy.log

[OUTPUT]
Name http
Match *
URI /api/v1/fluentbit-logs/ingest
Host localhost
Port 7280
tls Off
Format json_lines
Json_date_key timestamp
Json_date_format epoch

Fluentbit 将把 dummy 日志发送到 Quickwit 的端点 /api/v1/fluentbit-logs/ingest

让我们启动 Fluentbit。

fluent-bit -c fluent-bit.conf

搜索日志

Quickwit 现在正在从 Fluentbit 接收日志,并且您可以使用 cURL 或通过 UI 进行搜索:

  • curl "http://127.0.0.1:7280/api/v1/fluentbit-logs/search?query=severity:DEBUG"
  • 在浏览器中打开 http://127.0.0.1:7280/ui/search?query=severity:DEBUG&index_id=fluentbit-logs&max_hits=10.

进一步改进

您很快就能对动态字段执行聚合操作(计划在 0.7 版本中实现)。