溫馨提示×

Debian下如何自定義Filebeat的日志輸出格式

小樊
45
2025-07-25 03:33:40
欄目: 智能運維

在Debian系統下,要自定義Filebeat的日志輸出格式,你需要修改Filebeat的配置文件。以下是具體步驟:

  1. 打開Filebeat配置文件。默認情況下,該文件位于/etc/filebeat/filebeat.yml。使用文本編輯器打開它,例如使用nano編輯器:
sudo nano /etc/filebeat/filebeat.yml
  1. filebeat.yml文件中,找到output.elasticsearch部分。如果你還沒有配置輸出到Elasticsearch,請添加以下內容:
output.elasticsearch:
  hosts: ["localhost:9200"]

localhost:9200替換為你的Elasticsearch實例的地址和端口。

  1. output.elasticsearch部分下,添加fields_under_root設置,將其設置為true。這將使Filebeat將所有事件字段放在Elasticsearch文檔的根級別,而不是嵌套在fields字段中。
output.elasticsearch:
  hosts: ["localhost:9200"]
  fields_under_root: true
  1. filebeat.yml文件中,找到fields部分。在這里,你可以添加自定義字段,這些字段將附加到每個事件中。例如:
fields:
  custom_field1: "value1"
  custom_field2: "value2"
  1. 保存并關閉filebeat.yml文件。

  2. 重新啟動Filebeat服務以應用更改:

sudo systemctl restart filebeat

現在,Filebeat將以自定義的格式輸出日志。你可以在Elasticsearch中查看事件,看到自定義字段已添加到文檔中。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女